By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

Print to printer

P: n/a
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


P: n/a
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

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

Oct 31 '05 #3

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

Oct 31 '05 #4

P: n/a
avnit wrote:
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?


Mac OSX is unix, right?

This ought to work then:
import os
printer = os.popen('lpr', 'w')
printer.write('This is a test.\n')
printer.close()


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

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

Nov 5 '05 #6

P: n/a
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:
printer.write(file('path/to/file.ext'))


but apparently this function only takes strings as parameters.

Thanks.

Nov 5 '05 #7

P: n/a
avnit wrote:
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:
printer.write(file('path/to/file.ext'))


but apparently this function only takes strings as parameters.


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

This discussion thread is closed

Replies have been disabled for this discussion.