我是python3的新手,尝试从包含字符串和字节的字节数组中提取消息。你知道吗
我无法从解码的字节数组中提取字节消息。你知道吗
我尝试使用bytes(v) for v in rest.split()
函数来获取字节数组,然后对其进行解码,但未能成功。你知道吗
# The message chunk:
chunk = b"1568077849\n522\nb'l5:d4:auth53:\xc3\x99\xc3\xac\x1fH\xc2\xa3ei6eli1eee'\n"
# I split the chunk into sub categories for further processing:
_, size, rest = (chunk.decode("utf-8")).split('\n', 2)
# _ contains "1568077849"
# size contains "522"
# rest contains "b'l5:d4:auth53:\xc3\x99\xc3\xac\x1fH\xc2\xa3ei6eli1eee'"
我应该可以解码rest变量(休息。解码(“utf-8”)),但由于它被存储为字符串,我很难弄清楚如何将其转换为字节,然后对值进行解码。你知道吗
预期结果:l5:d4:auth53:ÙìH£ei6eli1eee
这将打印您的最终结果:
我可以这样得到预期的输出:
从这篇文章中得到了线索: Process escape sequences in a string in Python
相关问题 更多 >
编程相关推荐