string <-> byte in python
To transform a unicode string to a byte string in Python do this:
>>> 'foo'.encode('utf_8')
b'foo'
To transform a byte string to a unicode string:
>>> b'foo'.decode('utf_8')
'foo'
To convert a string to bytes.
data = "" #string data = "".encode() #bytes data = b"" #bytes
To convert bytes to a String.
data = b"" #bytes data = b"".decode() #string data = str(b"") #string
标签:无