thelastWallE / OctoprintKlipperPlugin

A plugin for a better integration of Klipper into OctoPrint.
GNU Affero General Public License v3.0
65 stars 14 forks source link

Fix performance graph can't read log with Python 3 #25

Closed Master92 closed 3 years ago

Master92 commented 3 years ago

Closes #21

With Python 2 it seems that Strings prefixed with b are converted to text strings implicitly:

>>> s = b'Hello World'
>>> print(s)
Hello World
>>> line = s.split()
>>> print(line)
['Hello', 'World']
>>> if ('Hello' in line):
...     print("true")
... else:
...     print("false")
...
true

In Python 3 this is not the case:

>>> s = b'Hello World'
>>> print(s)
b'Hello World'
>>> line = s.split()
>>> print(line)
[b'Hello', b'World']
>>> if ('Hello' in line):
...     print("true")
... else:
...     print("false")
...
false

My approach is to parse the log file in text mode, as I don't understand why it was opened in binary mode in the first place. I've tested my code with OctoPrint 1.5.1, Python 2.7.18 and Python 3.8.6 on my Windows machine and OctoPrint 1.5.1 and Python 3.9.0 on my Raspberry Pi 3.