# 1.已知:
'你好'.encode()
# 输出
b'\xe4\xbd\xa0\xe5\xa5\xbd' # bytes
# ----------------------------------------------
# 现在拥有
'\xe4\xbd\xa0\xe5\xa5\xbd' # type: str
# 需要转化为(关键是 这一步转化不会)
b'\xe4\xbd\xa0\xe5\xa5\xbd' # type: bytes
# 得到:
'你好'
有大佬会做吗?
或者说 除了 encode() 怎么构造出 bytes 类型
str1='\xe4\xbd\xa0\xe5\xa5\xbd'
print(bytes(ord(i) for i in str1))
result = []
s = '你的字符串'
for i in s:
a = struct.pack("B", ord(i) / 256)
b = struct.pack("B", ord(i) % 256)
result.append(a)
result.append(b)