Python 3:文字列をバイトに変換
string
をbytes
に、またはその逆に変換する方法を示すコードスニペット。
1. 文字列をバイトに変換します。
data = "" #string data = "".encode() #bytes data = b"" #bytes
2. バイトを文字列に変換します。
data = b"" #bytes data = b"".decode() #string data = str(b"") #string
P.S Tested with Python 3.4.3