Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python print to /dev/usb/lp0

I would like print to /dev/usb/lp0 from my python code. In bash it is very simple: echo 'apple' >/dev/usb/lp0

I found linemode, but this is not working. When I try to install it I get these errors.

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

How I print to /dev/usb/lp0 from python code?

like image 254
user3740961 Avatar asked Feb 12 '26 07:02

user3740961


1 Answers

This is working:

 with open('/dev/usb/lp0', 'w') as printer:
            printer.write("Line 1\n")
            printer.write("Line 2\n")
like image 70
user3740961 Avatar answered Feb 15 '26 08:02

user3740961



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!