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!")
GHOSTSCRIPT_PATH = "C:path oGHOSTSCRIPTingswin32.exe"
GSPRINT_PATH = "C:path oGSPRINTgsprint.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)