Printing to printer

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


Kristian Zoerhoff <kristian.zoerhoff at gmail.com> writes:

> On 8/11/05, Steve M <steve at myplace.com> wrote:
>> Kristian Zoerhoff wrote:
>> 
>> > On 8/11/05, Steve M <steve at myplace.com> 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
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list