相关疑难解决方法(0)

多行的python pprint词典

我正试图获得一本字典的印刷品,但我没有运气:

>>> import pprint
>>> a = {'first': 123, 'second': 456, 'third': {1:1, 2:2}}
>>> pprint.pprint(a)
{'first': 123, 'second': 456, 'third': {1: 1, 2: 2}}
Run Code Online (Sandbox Code Playgroud)

我希望输出在多行上,如下所示:

{'first': 123,
 'second': 456,
 'third': {1: 1,
           2: 2}
}
Run Code Online (Sandbox Code Playgroud)

可以pprint这样吗?如果没有,那么哪个模块呢?我正在使用Python 2.7.3.

python dictionary python-2.7 pprint

61
推荐指数
3
解决办法
6万
查看次数

标签 统计

dictionary ×1

pprint ×1

python ×1

python-2.7 ×1