0

when running in python2, i get the result like this:

DEBUG:__main__:ASIC EEG Power: EEGPowerData(delta=7784, theta=7734, lowalpha=2035, highalpha=1979, lowbeta=2914, highbeta=3996, lowgamma=1944, midgamma=1847

when running in python3, the result is like this:

DEBUG:__main__:ASIC EEG Power: b'\x00\xa9\xf1\x00t%\x00\rK\x00\x18"\x00\x16%\x00\x1d6\x00OT\x00\x17\x84'

Anyone know how should i edit this line of code in order to make it work in python 3? Thank you

_decode = staticmethod(lambda v: EEGPowerData(*struct.unpack('>8L', ''.join( '\x00'+v[o:o+3] for o in range(0, 24, 3)))))
  • what's in the buffer and how do you fill that buffer? Any unicode char in a string would return itself as byte array instead of a string as in py2. – SMA Jan 31 '21 at 14:25
  • I think in that buffer is all byte code like "\xaa", the buffer is read from bluetooth. so how can I make it return a string in python 3? Thank you – Zizhao Zhang Jan 31 '21 at 14:29
  • Use something like `import six; data = six.ensure_text(mybytes) ##If you want to process as a string; ##Do further processing` – SMA Jan 31 '21 at 14:30
  • so does it mean I should change line 78 to buf = six.ensure_text(self.io.read(n))? – Zizhao Zhang Jan 31 '21 at 14:32
  • Yes try that out. – SMA Jan 31 '21 at 14:33
  • thanks. it report error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaa in position 0: invalid start byte – Zizhao Zhang Jan 31 '21 at 14:35
  • So in your ensure_text you can pass encoding as well like `ensure_text(mybytes, encoding='latin-1')` – SMA Jan 31 '21 at 14:36
  • I think it's still not decoding properly. – Zizhao Zhang Jan 31 '21 at 14:39
  • DEBUG:__main__:Unknown: code=80 extended_code_level=0 '\xff��' DEBUG:__main__:Unknown: code=80 extended_code_level=0 '\x00\x08' DEBUG:__main__:Unknown: code=80 extended_code_level=0 '\x00\x0b' DEBUG:__main__:Unknown: code=80 extended_code_level=0 '\x00\x10' DEBUG:__main__:Unknown: code=80 extended_code_level=0 '\x00\x0c' DEBUG:__main__:Unknown: code=80 extended_code_level=0 '\x00\x15' – Zizhao Zhang Jan 31 '21 at 14:40
  • anyone could please help me with the problem? thank u!!! – Zizhao Zhang Jan 31 '21 at 15:22

0 Answers0