繁体   English   中英

将元组中的字节转换为字符串

[英]Converting bytes inside a tuple to string

我有一个充满字节的元组,我需要将这些字节转换为一个 utf-8 字符串,我该怎么做?

data = tuple([0, 4, 4, 6, 1, 53])
print(data as utf-8 string?)
data = bytes(tuple([0, 4, 4, 6, 1, 53])).decode('utf-8')

输出:

'\x00\x04\x04\x06\x015'

使用的功能:

bytes() - convert an iterable to a bytes like object
decode('utf-8') - decode bytes to utf8

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM