bytes是二进制形式的字符串,
dict是可变容器(键值对)模型,且可存储任意类型对象
方法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转dict用eval方法就可以
str和bytes相互转换
# 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)