Oct-12-2019, 09:55 PM
(Oct-09-2019, 05:59 PM)Gribouillis Wrote: Could it be an error similar to this one ?
>>> rom_bytes = b'hello world' >>> import struct >>> struct.unpack("I", rom_bytes[4]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: a bytes-like object is required, not 'int' >>> struct.unpack("I", rom_bytes[:4]) (1819043176,)
I don't understand why would be, since is a different error message.
Anyway, I don't know why, but now the code is working on python 3.2, since it converts the values to int. However in 2.6 where the type is 'str', first I receive
Quote:self.data_bytes = rom_bytes [HEADER_SIZE:HEADER_SIZE + (16 + KB_SIZE *(self.num_prg_blocks))]
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Then adding a int before with:
self.data_bytes = rom_bytes [HEADER_SIZE:HEADER_SIZE + (16 + KB_SIZE * int (self.num_prg_blocks))]I receive:
Quote:ValueError: invalid literal for int() with base 10: '\x02'
finally doing this:
self.temp = self.num_prg_blocks struct.unpack ("I", self.temp) self.data_bytes = rom_bytes [HEADER_SIZE:HEADER_SIZE + (16 + KB_SIZE * self.temp)]makes me receive on python 2.6
Quote:struct.error: unpack requires a string argument of length 4
and on python 3.2
Quote:TypeError: 'int' does not support the buffer interface
What shall be my next step?