“Wydrukuj plik w Python” Kod odpowiedzi

Python zapisz do pliku

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

Plik druku 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

Wydrukuj plik w 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

Odpowiedzi podobne do “Wydrukuj plik w Python”

Pytania podobne do “Wydrukuj plik w Python”

Więcej pokrewnych odpowiedzi na “Wydrukuj plik w Python” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu