
当我运行'print(abide.description)‘命令时,我应该得到这样的输出,但是我得到的输出是这样的。整个字符串显示在一行中,这使得读取和解释非常困难。如何获得上图所示的输出?
我的代码片段:
print(abide.description)输出:

发布于 2020-09-22 01:31:16
问题是abide.description返回的是字节而不是字符串。如果希望它作为普通字符串打印,可以使用bytes.decode()方法将字节转换为unicode字符串。
例如:
content_bytes = b'this is a byte string\nand it will not be wrapped\nunless it is first decoded'
print(content_bytes)
# b'this is a byte string\nand it will not be wrapped\nunless it is first decoded'
print(content_bytes.decode())
# this is a byte string
# and it will not be wrapped
# unless it is first decodedhttps://stackoverflow.com/questions/63992528
复制相似问题