在 python pdb 中打印 \n 换行符作为实际换行符

Print \n newline as actual newline in python pdb

当我在 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) print(large_string)
very large string with newline
another line in the large string

etc
(Pdb)

如果你使用Python 2.x你可以导入打印功能:

from __future__ import print_function

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

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

!print large_string