Bytearray Question #10032
-
I need to boot a peripheral device from an
Is it correct for me to simply declare this as a
When I print |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@A622266 Yep that's right, this is standard Python behavior -- bytes and bytearrays are printed as strings, where only the "unprintables" are escaped. I would recommend instead making your tool print out the same format as Python prints i.e.
This has the added benefit of using less memory when loading your program, as the initial consutrction of the list uses 4x as much RAM (because the bytes will be promoted to integers, only to be truncated back down to bytes when creating the bytearray). If you want to verify the data use
|
Beta Was this translation helpful? Give feedback.
@A622266 Yep that's right, this is standard Python behavior -- bytes and bytearrays are printed as strings, where only the "unprintables" are escaped.
I would recommend instead making your tool print out the same format as Python prints
i.e.
program = b'\x00\x00\x00\x00\x00\xfe\xe0\x00....'
This has the added benefit of using less memory when loading your program, as the initial consutrction of the list uses 4x as much RAM (because the bytes will be promoted to integers, only to be truncated back down to bytes when creating the bytearray).
If you want to verify the data use
print(program.hex(','))