[Tutor] Output to a printer

Alan Gauld alan.gauld at blueyonder.co.uk
Thu May 6 14:06:09 EDT 2004


> I am learning Python on a Windows system (Win95).  All of the
tutorials,
> documentation, and a book that I am studying all assume printing to
the
> console (stdout).

That's coz its easy! :-)

> I live in the real world and will need to print out to
> my laser printer or other device.  How do I modify the print or
write
> statements, or redirect stdout, to print to a printer?

On Win 95 its also easy for text at least.
Just open the 'LPT1:' or 'PRN:' device as if it were a file for
writing and squirt the text to it. Unfortunately that won't work
on later versions of Windsows (NW"K and XP variants specifically).
Nor does it work easily for fancy formatting.

THis is a problem in all programming languages on Windows because
basically Windows treats documents to be printed as graphics, so
you have to convert your document into something windows can print.
Its possible but painful (unless you find a module somewhere,
in which case let me know!)

Meantime I generally generate HTML as a temporary file then print
that via my web broweser, either by hand or using COM or the os.system
function.

You can also generate PDF or RTF via supporting modules and print
them in a similar way (using Acrobat/ghostview/Word etc)

On Unix its slightly easier because the printer is again a file
type device...

HTH

Alan G.





More information about the Tutor mailing list