【问题标题】:Python print to /dev/usb/lp0Python 打印到 /dev/usb/lp0
【发布时间】:2016-02-22 09:40:41
【问题描述】:

我想从我的 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

【问题讨论】:

  • 如果你想发送一些东西到打印机,这里是解决方案:stackoverflow.com/questions/13059930/…
  • 奋斗者:如果我想写入文件:这没问题。但我想使用 /dev/usb/lp0 然后我得到错误: Permission denied: '/dev/usb/lp0'
  • 您可以只创建一个常规文本文件并使用 lpr 命令行工具打印此文件。
  • Alexander Baltasar:这不是一个很好的解决方案。
  • 我创建了常规文本文件并编写了这个 python 代码: subprocess.call("cat file > /dev/usb/lp0", shell=True) 但这不起作用。 (没有错误)但是这个 bash 正在工作: cat file > /dev/usb/lp0 为什么?

标签: python linux bash printing usb


【解决方案1】:

这是有效的:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多