在 Google Colab 中查看字符串输出时出现问题

https://img2.mukewang.com/64e462a00001835306490311.jpg

当我运行命令“print(abide.description)”时,我应该获得这样的输出,但我获得的输出是这样的。整个字符串显示在一行中,这使得阅读和解释变得非常困难。如何获得如上图所示的输出?

我的代码片段:

print(abide.description)

输出:

https://img4.mukewang.com/64e462af00015a4f12680096.jpg

繁星点点滴滴
浏览 1574回答 1
1回答

qq_笑_17

问题是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 decoded
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python