Oct-15-2019, 03:17 PM
(Oct-12-2019, 10:39 PM)Gribouillis Wrote:colt Wrote:I don't know why, but now the code is working on python 3.2, since it converts the values to int.That's because in python 3 a bytes string is a sequence of small integers:
>>> # python 3 >>> x = b'\x02' >>> x[0] 2in python 2
>>> # python 2 >>> x = '\x02' >>> x[0] '\x02'In python 2 you can convert a one character string to int by using the ord function
>>> ord(x[0]) 2But when callingstruct.unpack ("I", self.temp)
, make sure self.temp is a 4 bytes string.
Finally, do you have to use python 2? Don't use it, it's dead.
Tried
self.num_prg_blocks = ord (self.header [4])and it solved this issue with old python, but with the new python I receive:
Quote:TypeError: ord() expected string of length 1, but int found
To answer, I do not HAVE to use it, as mandatory