我正试图获得一本漂亮的字典,但我没有运气:
>>> import pprint
>>> a = {'first': 123, 'second': 456, 'third': {1:1, 2:2}}
>>> pprint.pprint(a)
{'first': 123, 'second': 456, 'third': {1: 1, 2: 2}}
我希望输出多行,如下所示:
{'first': 123,
'second': 456,
'third': {1: 1,
2: 2}
}
pprint
可以这样做吗?如果不是,那么它是哪个模块?我正在使用 Python 2.7.3 。
最佳答案
使用 width=1
或 width=-1
:
In [33]: pprint.pprint(a, width=1)
{'first': 123,
'second': 456,
'third': {1: 1,
2: 2}}
关于python - pprint 字典在多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20171392/