Print to standard printer from Python?

Prof. Falken picture Prof. Falken · Oct 4, 2012 · Viewed 124.7k times · Source

Is there a reasonably standard and cross platform way to print text (or even PS/PDF) to the system defined printer?

Assuming CPython here, not something clever like using Jython and the Java printing API.

Answer

user3444876 picture user3444876 · Mar 21, 2014

This has only been tested on Windows:

You can do the following:

import os

os.startfile("C:/Users/TestFile.txt", "print")

This will start the file, in its default opener, with the verb 'print', which will print to your default printer.Only requires the os module which comes with the standard library