Python打印到/ dev / usb / lp0

时间:2016-02-22 09:40:42

标签: python linux bash printing usb

我想从我的python代码打印到/dev/usb/lp0。在bash中,它非常简单:echo 'apple' >/dev/usb/lp0

我找到linemode,但这不起作用。当我尝试安装它时,我遇到了这些错误。

byte-compiling build/bdist.linux-x86_64/egg/linemode/renderers/xml.py to xml.pyc
File "build/bdist.linux-x86_64/egg/linemode/renderers/xml.py", line 67
def __init__(self, source, *, max_width=None, prelude=True):
                            ^
SyntaxError: invalid syntax

我如何从python代码打印到/dev/usb/lp0

1 个答案:

答案 0 :(得分:3)

这是有效的:

 with open('/dev/usb/lp0', 'w') as printer:
            printer.write("Line 1\n")
            printer.write("Line 2\n")