问题描述
当我在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
"
有小费吗?
1楼
只需调用正常的打印功能:
(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
3楼
您可以使用'!'为任何Python命令添加前缀,因此这也适用于Python 2.x:
!print large_string