[英]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.