Printing in a generic way - like the rest of Python

Ed Connell connell at noflashspam.net
Tue May 13 05:02:32 EDT 2003


"Thomas Heller" <theller at python.net> wrote in message
news:7k8vl4fj.fsf at python.net...
> > > >How can I print a file in a generic way in both Widows and Linux?
I've
> > > >searched for the answer but have not found it.
> > >
> > > I assume you mean something more than basic ASCII text?
> > >
> >
> > No, I mean something as simple as printing an ASCI text file. (I mean
> > sending the file to the system printer.)  My program ran just fine in
Linux,
> > (I used system( 'lpr %s' % filename ) and it worked just fine.  Now I
want
> > to make the same program run in MS-Windows, and wondered if there is
some
> > generic way to send files to the printer as there are generic ways to
delete
> > a file, say, and all sorts of other stuff.
>
> 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()
>
> Thomas

Thank you, Thomas.  I'd like to find a generic routine, but perhaps I'll
have to ask os what kind of system it's running on and the use conditionals
to do the appropriate thing.

Ed





More information about the Python-list mailing list