在Python的pdb中,如何将打印出来的\n换行符显示为实际的换行符?

4

当我在pdb中并且有一个很长的字符串时,有时我想将它打印出来并显示为实际的换行符,而不是在终端中看到它们被表示为\n。

(Pdb) p large_string
"very large string with newline\nanother line in the large string\n\netc\n"

我更愿意看到

(Pdb) printwithnewline large_string
"very large string with newline
another line in the large string

etc
"

有什么建议吗?


(在使用pdb打印内容时,您还应该检查pp,它可以进行漂亮的打印,对于列表和字典非常方便) - spectras
3个回答

6

只需调用普通的打印函数:

(Pdb) print(large_string)
very large string with newline
another line in the large string

etc
(Pdb)

2
如果您使用Python 2.x版本,您可以导入打印函数:
from __future__ import print_function

(Pdb) print(large_string)
very large string with newline
another line in the large string

0

你可以在任何Python命令前加上'!',这对于Python 2.x也适用:

!print large_string

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接