Printing in a generic way - like the rest of Python
Anders J. Munch
andersjm at dancontrol.dk
Tue May 13 06:35:38 EDT 2003
"Ed Connell" wrote:
> "Thomas Heller" wrote:
> > I just tried this, and it worked (on XP pro, with a printer connected
> > via network):
> >
> > p = open("lpt1:", "w")
> > p.write("Hello, World\n")
> > p.close()
> >
Alas, this doesn't necessarily do anything useful. lpt1: is just the
name of a parallel port; while it _may_ be redirected to a network
printer, the port may also be in use for other things.
> If the answer is no, then my next question is, how do you print a file in
> the Windows world. I feel foolish asking, but for the life of me, can't
> figure what to do. I tried 'print filename' from a command prompt, but
> things didn't happen.
Yes, you would expect 'print filename' to work, wouldn't you. It just
doesn't, it's a piece of junk left over from MS-DOS.
MS Windows printing is tied into the GUI system, which works with
stuff like qdevice contexts, fonts and absolute control over page
layout. There is no print system support for simple text files.
There are, however, simple text applications that can be hijacked for
this purpose. Try
os.system("notepad /p filename.txt")
- Anders
More information about the Python-list
mailing list