Nov-21-2022, 05:36 PM
I am a new Python developer.
Albeit new, I come from a C background.
I have a file of bytes I want to read into a bytearray() object. SOME of the byte values are getting converted to an ascii value instead of remaining as a byte value. I must be missing an obvious point.
fh = open(filename, 'rb')
ba = bytearray(fh.read())
fh.close()
Example:
Here are five byte values in the file (I use a Hex editor HxD):
0F 9B 63 69 67
After reading the values into the array, the 0F and 9B are imported fine. However, instead of three separate byte values, 63, 69, and 67, I just have "cig".
Logged Result:
bytearray "\x0f\x9bcig\x00"
This appears to be happening for larger bytes but not always 'decimal appearing' values. 10 and 17 for example, are imported fine.
What can I do to circumvent this problem?
Innovative ideas are welcome!
Thank you sincerely!
chepilo
Albeit new, I come from a C background.
I have a file of bytes I want to read into a bytearray() object. SOME of the byte values are getting converted to an ascii value instead of remaining as a byte value. I must be missing an obvious point.
fh = open(filename, 'rb')
ba = bytearray(fh.read())
fh.close()
Example:
Here are five byte values in the file (I use a Hex editor HxD):
0F 9B 63 69 67
After reading the values into the array, the 0F and 9B are imported fine. However, instead of three separate byte values, 63, 69, and 67, I just have "cig".
Logged Result:
bytearray "\x0f\x9bcig\x00"
This appears to be happening for larger bytes but not always 'decimal appearing' values. 10 and 17 for example, are imported fine.
What can I do to circumvent this problem?
Innovative ideas are welcome!
Thank you sincerely!

chepilo