当前位置: 代码迷 >> python >> 打印\ n换行作为python pdb中的实际换行符
  详细解决方案

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

热度:66   发布时间:2023-06-16 13:59:28.0

当我在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
  相关解决方案