0

I am working on editing this package from python 2 to python 3 because I need use KivyMD, which only support python3. source code can be found here: [https://github.com/groner/pythinkgear/tree/master/thinkgear]

When running under python 2, it can output the desired results like this:

DEBUG:__main__:ASIC EEG Power: EEGPowerData(delta=3656, theta=5612, lowalpha=697, highalpha=3450, lowbeta=6125, highbeta=5826, lowgamma=2728, midgamma=53552)
DEBUG:__main__:ATTENTION eSense: 0
DEBUG:__main__:MEDITATION eSense: 0
DEBUG:__main__:POOR SIGNAL: 200
DEBUG:__main__:ASIC EEG Power: EEGPowerData(delta=1340, theta=5046, lowalpha=4464, highalpha=5822, lowbeta=2467, highbeta=4815, lowgamma=8844, midgamma=57809)
DEBUG:__main__:ATTENTION eSense: 0
DEBUG:__main__:MEDITATION eSense: 0

In order to make it run on python 3, I edited line 31 to this:

from io import StringIO ## for Python 3

and line 91 from:

_bytelog.debug('%04X  '+' '.join(('%02X',)*len(buf[o:o+16])), o, *( ord(c) for c in buf[o:o+16] ))

to this:

_bytelog.debug('%04X  '+' '.join(('%02X',)*len(buf[o:o+16])), o, *(c for c in buf[o:o+16]))

also I have changed all "xrange" function to "range".

But the result I get(without any error reported) is this:

DEBUG:__main__:discarding b'\xaa' while syncing
DEBUG:__main__:discarding b'\xaa' while syncing
DEBUG:__main__:discarding b'\x04' while syncing
DEBUG:__main__:discarding b'\x80' while syncing
DEBUG:__main__:discarding b'\x02' while syncing
DEBUG:__main__:discarding b'\x00' while syncing
DEBUG:__main__:discarding b'-' while syncing
DEBUG:__main__:discarding b'P' while syncing
DEBUG:__main__:discarding b'\xaa' while syncing
DEBUG:__main__:discarding b'\xaa' while syncing
DEBUG:__main__:discarding b'\x04' while syncing
DEBUG:__main__:discarding b'\x80' while syncing
DEBUG:__main__:discarding b'\x02' while syncing
DEBUG:__main__:discarding b'\x00' while syncing
DEBUG:__main__:discarding b'Q' while syncing
DEBUG:__main__:discarding b',' while syncing
DEBUG:__main__:discarding b'\xaa' while syncing
DEBUG:__main__:discarding b'\xaa' while syncing
DEBUG:__main__:discarding b'\x04' while syncing

all are binary code instead of numerical result. Can anyone please tell me the reason? or is there any place I still need edit in order to make this package work in python 3? Thank you very much!!!

zzz
  • 1
  • 1
  • Notice that your error messages are all about bytestrings. You are almost certainly running into the problem that bytestings are distinct from strings in Python 3 but essentially the same thing in Python 2. This is one of the trickiest things to fix in a Python 3 migration because it often needs an understanding of the intent of the original code, that goes beyond simple syntactic fixes and name changes, which can nearly all be done by `lib2to3` anyway, and so are a waste of time to do by hand. Anyone who can offer meaningful help will have already upgraded that specific module themselves. – BoarGules Jan 29 '21 at 11:09
  • Thank you BoarGules. The package was created almost 10 years ago. Unluckily I believe nobody would be using it any more, I have also pulled request in GitHub but I think hard to get an answer – zzz Jan 29 '21 at 12:58
  • It looks like the project owner lost interest, or concluded that porting to Python 3 was not worth the effort. Your best option might be to use the hardware vendor's sample C code (together with the Python 2 translation you have) as a basis for writing a new Python 3 module from scratch. Not what you wanted, I know, but it might be less hassle than futzing with the awkward corner cases of Python 2/3 incompatibility. – BoarGules Jan 29 '21 at 14:17
  • Oh I’m not familiar with C. I’ve tried to run the C code and it worked but I don’t understand it. I thought the easiest way is to edit the python 2 version. – zzz Jan 29 '21 at 15:17

0 Answers0