adafruit / Python-Thermal-Printer

216 stars 148 forks source link

SyntaxError - please help - #37

Open cridder opened 4 years ago

cridder commented 4 years ago

i reinstalled and updated from this repo.

any suggestions.

thanks.

pi@raspberrypi:~/Python-Thermal-Printer $ python printertest.py Traceback (most recent call last): File "printertest.py", line 3, in from Adafruit_Thermal import File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 725 def print(self, args, **kwargs): ^ SyntaxError: invalid syntax

zackdotcomputer commented 4 years ago

I'm also encountering this - I just commented out that function and the println function for now

zackdotcomputer commented 4 years ago

Ok so what did it for me in the end was changing my calls to use sudo python3 rather than plain-old sudo python even though I have python alias'd to python3 on my machine. IDK enough about linux and/or python to know why, though.

anyu commented 4 years ago

^Right, or change the first line in the sample scripts to #!/usr/bin/python3

When printer.println is called in the examples, the imported printer library tries to overload Python's built-in print with its own. In Python 2, print is a statement rather than a function, so it can't be overloaded and the syntax error is thrown. In Python 3, print changed from a statement to a function, so it can be successfully overloaded.

https://github.com/adafruit/Python-Thermal-Printer/blob/3e7be0b72ca04f850cf5101e236198a35bae0824/Adafruit_Thermal.py#L722-L733