正常print一个dict,显示内容是全部在一行的。如下
di = {"name":"test1", "sex":"test2", "others":[1,2,"3"]}
print di
{'others': [1, 2, '3'], 'name': 'test1', 'sex': 'test2'}
内容少,还能看得明白,多了就不明朗了,用json库能格式化
import json
di = {"name":"test1", "sex":"test2", "others":[1,2,"3"]}
print json.dumps(di, indent=4)
打印如下:
{
"others": [
1,
2,
"3"
],
"name": "test1",
"sex": "test2"
}