“Imprimir archivo en Python” Código de respuesta

Python escribir en el archivo

file = open(“testfile.txt”,”w”) 
 
file.write(“Hello World”) 
file.write(“This is our new text file”) 
file.write(“and this is another line.”) 
file.write(“Why? Because we can.”) 
 
file.close() 
Misty Macaw

Archivo de impresión de Python

import sys

# only this print call will write in the file
print("Hello Python!", file=open('output.txt','a'))

# not this one (std output)
print("Not written")

# any further print will be done in the file
sys.stdout = open('output.txt','wt')
print("Hello Python!")
VasteMonde

Imprimir archivo en Python

GHOSTSCRIPT_PATH = "C:\\path\\to\\GHOSTSCRIPT\\bin\\gswin32.exe"
GSPRINT_PATH = "C:\\path\\to\\GSPRINT\\gsprint.exe"

# YOU CAN PUT HERE THE NAME OF YOUR SPECIFIC PRINTER INSTEAD OF DEFAULT
currentprinter = win32print.GetDefaultPrinter()

win32api.ShellExecute(0, 'open', GSPRINT_PATH, '-ghostscript "'+GHOSTSCRIPT_PATH+'" -printer "'+currentprinter+'" "PDFFile.pdf"', '.', 0)
Iniyan V

Respuestas similares a “Imprimir archivo en Python”

Preguntas similares a “Imprimir archivo en Python”

Más respuestas relacionadas con “Imprimir archivo en Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código