Print to Paper
Piet van Oostrum
piet-l at vanoostrum.org
Fri Oct 4 11:43:28 EDT 2019
Daniel <duram at terra.com.br> writes:
> How to do a code to print to paper? please post here a "Hello World"
> code to be printed on paper with an inkjet.
> Thanks
> Daniel
It depends on the Operating System. Python doesn't have a standard, system-independent way to print to paper.
On most Unix-like systems (like my MacOS) the following works:
from subprocess import Popen, PIPE
p = Popen('lpr', stdin=PIPE)
p.communicate(b'Hello World')
p.stdin.close()
p.wait()
In a production system error checking should be added. Also if a nice layout is desired, you should probably want to generate a PDF file and send that to the printer, possibly with the use of LaTeX.
--
Piet van Oostrum <piet-l at vanoostrum.org>
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]
More information about the Python-list
mailing list