On 9/30/2021 at 4:44 AM, rje said:
Hey, that doesn't write bytes to the output channel, it creates a text file containing the Python expression "[12, 13, 14, 0, 80, 0, 90, 0, 10, 0, 12, 13, 14]". The binary file should have 12 bytes in it, since there are 12 byte values in the concatted array. Maybe I'm doing something wrong?
Just tested it, and that's what happens in Python 2. In Python 3 it does indeed write a binary file. In Python 2 it is "bytearray()" instead of "bytes()", then it works as intended. Not sure why "bytes()" doesn't throw an error in Python 2.
On 9/29/2021 at 7:34 PM, rje said:
Note that he has to first break down larger numbers, and encode strings into bytes. He might have to do some custom coding if endianness is a problem.
Partially true. You can convert other things into bytearrays. E.g. appending a 16-bit integer to a bytearray is
existing_bytearray += (65535).to_bytes(2,"little")
where the argument 2 states that it should become 2 bytes, and "little" or "big" endian can be used. There's also an option for signed integers. Strings can be dealt with as
existing_bytearray += ("hello world").encode("utf-8")
Although encoding strings to PETSCII may require some extra code...