can you print a file from python?

后端 未结 3 1933
清歌不尽
清歌不尽 2020-12-19 19:39

Is there some way of sending output to the printer instead of the screen in Python? Or is there a service routine that can be called from within python to print a file? Mayb

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 20:24

    Python doesn't (unless you're using graphical libraries) ever send stuff to "The screen". It writes to stdout and stderr, which are, as far as Python is concerned, just things that look like files.

    It's simple enough to have python direct those streams to anything else that looks like a file; for instance, see Redirect stdout to a file in Python?

    On unix systems, there are file-like devices that happen to be printers (/dev/lp*); on windows, LPT1 serves a similar purpose.

    Regardless of the OS, you'll have to make sure that LPT1 or /dev/lp* are actually hooked up to a printer somehow.

提交回复
热议问题