當(dāng)我運行命令“print(abide.description)”時,我應(yīng)該獲得這樣的輸出,但我獲得的輸出是這樣的。整個字符串顯示在一行中,這使得閱讀和解釋變得非常困難。如何獲得如上圖所示的輸出?我的代碼片段:print(abide.description)輸出:
1 回答

qq_笑_17
TA貢獻1818條經(jīng)驗 獲得超7個贊
問題是abide.description返回字節(jié)而不是字符串。如果你希望它作為普通字符串打印,你可以使用該bytes.decode()方法將字節(jié)轉(zhuǎn)換為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
添加回答
舉報
0/150
提交
取消