我有一个充满字节的元组,我需要将这些字节转换为单个utf-8字符串,我该怎么做?
data = tuple([0, 4, 4, 6, 1, 53])
print(data as utf-8 string?)
答案 0 :(得分:2)
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