Printing to printer

Mike Meyer mwm at
Sat Aug 13 02:28:58 CEST 2005

Kristian Zoerhoff <kristian.zoerhoff at> writes:

> On 8/11/05, Steve M <steve at> wrote:
>> Kristian Zoerhoff wrote:
>> > On 8/11/05, Steve M <steve at> wrote:
>> >> Hello,
>> >>
>> >>        I'm having problems sending information from a python
>> >> script to a printer. I was wondering if someone might send me
>> >> in the right direction. I wasn't able to find much by Google
>> >
>> > Which platform? Directions will vary wildly.
>> >
>> Ooops, sorry forgot to mention I'm using Suse 9.0 and Python 2.3x
> Assuming a local printer, you could just open the appropriate device
> file (e.g. /dev/lp0) in write mode and write the text to it. Another
> option would be to create a temp file, and then feed that to the lpr
> or enscript commands via the subprocess module.

There's a fair chance you have to be root to open the printer. Even if
you can, it won't work right if you've got a winprinter and are trying
to feed it ASCII. Likewise, if you're trying to feed it some pade
description language - HTML, PDF, PS, etc., that probably won't do the
right thing either.

Feeding your text to the lpr command should be the solution to all of
the above problems. The daemon that does the printing runs as
root. The printer configuration should transate whatever format you
feed it to something the printer can print.

Mike Meyer <mwm at>
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list