When using Python to do network programming will inevitably encounter convert a string to the byte stream,Here we record the following commonly used methods:
First byte array to a string,That is str:
1 2 3 4 5 |
b = b'some byte array' str(b, encoding = "utf-8") #or bytes.decode(b) |
Then the string to a byte array:
[crayon-673f88267bf3b5932[……]