364,111 Members | 2066 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Print to printer

avnit
P: n/a
avnit
I can't seem to figure out how to print with my printer using python.
I'm using Mac OSX 10.4. I was thinking maybe something with
applescript. Does anyone know?

Oct 28 '05 #1
Share this Question
Share on Google+
7 Replies


SPE - Stani's Python Editor
P: n/a
SPE - Stani's Python Editor
You should be more specific. What do you want to print? Text, images,
....
If you want a cross platform solution you could use wxPython:
http://wiki.wxwidgets.org/docbrowse....intingoverview

For text you could use wxHtmlEasyPrinting:
http://wiki.wxpython.org/index.cgi/Printing

For mac solutions, you better post this on the pythonmac mailing list.

Stani
--
http://pythonide.stani.be
http://pythonide.stani.be/manual/html/manual.html

Oct 29 '05 #2

avnit
P: n/a
avnit
I just want to print text. I'll try macpython. Thanks for the help.

Oct 31 '05 #3

avnit
P: n/a
avnit
I just want to print text. I'll try macpython. Thanks for the help.

Oct 31 '05 #4

Magnus Lycka
P: n/a
Magnus Lycka
avnit wrote:[color=blue]
> I can't seem to figure out how to print with my printer using python.
> I'm using Mac OSX 10.4. I was thinking maybe something with
> applescript. Does anyone know?[/color]

Mac OSX is unix, right?

This ought to work then:[color=blue][color=green][color=darkred]
>>> import os
>>> printer = os.popen('lpr', 'w')
>>> printer.write('This is a test.\n')
>>> printer.close()[/color][/color][/color]

Try to get 'lpr' or 'lp' to work from a command line.
You should be able to use 'lpstat -p' to figure out
printer names if you need that (then use 'lpr -P ps'
to print to a printer called ps.)
Nov 1 '05 #5

avnit
P: n/a
avnit
Wow. That worked perfectly. Thanks a lot.

Nov 5 '05 #6

avnit
P: n/a
avnit
Do you know if there's a way to print a file? I'm trying to print an
HTML file, so your solution is good, but doesn't really work for me.
Just reading the HTML file and the printing the content obviously
wouldn't work. I also tried:
[color=blue][color=green][color=darkred]
>>> printer.write(file('path/to/file.ext'))[/color][/color][/color]

but apparently this function only takes strings as parameters.

Thanks.

Nov 5 '05 #7

Magnus Lycka
P: n/a
Magnus Lycka
avnit wrote:[color=blue]
> Do you know if there's a way to print a file? I'm trying to print an
> HTML file, so your solution is good, but doesn't really work for me.
> Just reading the HTML file and the printing the content obviously
> wouldn't work. I also tried:
>[color=green][color=darkred]
> >>> printer.write(file('path/to/file.ext'))[/color][/color]
>
> but apparently this function only takes strings as parameters.[/color]

Unless you have a strong desire to waste time and memory by opening
the file reading the content into a string and then call printer.write,
you could simply do something along the lines of this:

fn = 'path/to/file.ext'
printer = 'ps'
print_cmd = 'lpr -P %s %s'
os.system(print_cmd % (printer, fn))
Nov 7 '05 #8

Post your reply

Help answer this question



Didn't find the answer to your Python question?

You can also browse similar questions: Python print python