2016-02-22 54 views
2

我想從我的python代碼打印到/dev/usb/lp0。在bash這很簡單:echo 'apple' >/dev/usb/lp0Python打印到/ 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

+0

如果你想送東西給打印機,這裏是解決方案: http://stackoverflow.com/questions/13059930/can-you-print-a-file-來自python – Striver

+0

Striver:如果我想寫入文件:這沒關係。但是我想使用/ dev/usb/lp0,然後出現錯誤:Permission denied:'/ dev/usb/lp0' – user3740961

+0

您可以創建一個常規文本文件並使用lpr命令行工具來打印該文件。 –

回答

2

這是工作:

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