I am writing a test that is intended to mutate binary data and ensure that my program can read the variations. Null bytes are an important part of this binary protocol.
When I try to save it, however, I encounter the error:
ValueError: source code string cannot contain null bytes
The assignment I'm currently trying is:
binary_blob = rb"""<value>"""
Where <value> has the hex representation 0x00.
How can I modify the assignment to avoid this error? I am using Python 3.9.5.
\0in the string literal.binary_blob = bytes([0x00])if you want to create abyteswith a0x00byte.'\0','\u0000', and'\x00'are all different ways to create a NULL character.