在python pdb中将换行打印为实际换行符

2024-06-16 11:15:28 发布

您现在位置:Python中文网/ 问答频道 /正文

当我在pdb中并且有一个大字符串时,有时我希望用换行符作为实际换行符打印出来,而不是在终端中看到它们。在

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

我宁愿看看

^{pr2}$

有什么提示吗?在


Tags: the字符串in终端stringwithlinenewline
3条回答

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

!print large_string

如果使用Python 2.x,则可以导入print函数:

from __future__ import print_function

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

只需调用正常打印函数:

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

etc
(Pdb)

相关问题 更多 >