How do I ‘declare’ an empty bytes variable?

Just use an empty byte string, b''.

However, concatenating to a string repeatedly involves copying the string many times. A bytearray, which is mutable, will likely be faster:

msg = bytearray()  # New empty byte array
# Append data to the array
msg.extend(b"blah")
msg.extend(b"foo") 

To decode the byte array to a string, use msg.decode(encoding='utf-8').

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)