2015-10-25 98 views
1

当我在pdb中时,我有一个大字符串,有时候我想用新行打印出来作为实际换行符,而不是在终端中将它们视为\ n 。在python 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 
" 

任何提示吗?

+0

(当你在打印pdb的东西的时候,你也应该检查一下'pp',它的确很漂亮打印,这是非常方便的列表和字典) – spectras

回答

2

只是正常调用打印功能:

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

etc 
(Pdb) 
1

如果您使用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