“Plik druku Python” Kod odpowiedzi

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

Jak zapisać do pliku wyjściowego w Pytion

#first arg is the name of the file
#second arg notes that the file is open to write to it
outputFile = open("fileName", "w")
#next line writes to the file
outputFile.write(str)
#remember to close opened files
outputFile.close()
NitroPog

Python Otwórz i odczytaj plik za pomocą

with open('pagehead.section.htm','r') as f:
    output = f.read()
Good Goshawk

z otwartym Pythonem

>>> with open('workfile') as f:
...     read_data = f.read()

>>> # We can check that the file has been automatically closed.
>>> f.closed
True
Powerful Platypus

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 “Plik druku Python”

Pytania podobne do “Plik druku Python”

Więcej pokrewnych odpowiedzi na “Plik druku Python” w Python

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

Przeglądaj inne języki kodu