bytes是二進(jìn)制形式的字符串,
dict是可變?nèi)萜?鍵值對(duì))模型,且可存儲(chǔ)任意類(lèi)型對(duì)象
方法1:
a={'Vod':'this is test'}}
r=bytes('{}'.format(a),'utf-8')
方法2:
map1 = {'aname':self.__ACCOUNT_NAME__}
b = json.dumps(map1).encode(encoding='utf-8')
由bytes轉(zhuǎn)dict用eval方法就可以
str和bytes相互轉(zhuǎn)換
# bytes object
b = b"simple"
# str object
s = "simple"
# str to bytes
bytes(s, encoding = "utf8")
# bytes to str
str(b, encoding = "utf-8")
# an alternative method
# str to bytes
str.encode(s)
# bytes to str
bytes.decode(b)