在python中将字节转换为字符串

2024-09-30 06:21:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用套接字从另一个系统返回了以下打印字节:

b"\x0bMessage Received!\r\x1c\r"

例如: print(b"\x0bMessage Received!\r\x1c\r".decode(encoding="utf-8"))

我得到了一份工作

Can you help me to understand how to get an output like this Message Received!从该消息中删除


Tags: toyou字节系统helpcanutfencoding
2条回答
b"\x0bMessage Received!\r\x1c\r".decode("utf-8")

您需要去掉不需要的字符(在本例中为垂直制表符和回车符):

>>> bs = b"\x0bMessage Received!\r\x1c\r"
>>> print(bs.decode().strip())
Message Received!

相关问题 更多 >

    热门问题