Print to printer

Magnus Lycka lycka at
Mon Nov 7 09:01:10 CET 2005

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))

More information about the Python-list mailing list