想获得漂亮的格式化字符串后输出,可以使用json.dumps() 的indent 参数。它会使得输出和pprint() 函数效果类似

>>> data
{'age': 4, 'name': 'niuniuche', 'attribute': 'toy'}
>>> import json
>>> print(json.dumps(data))
{"age": 4, "name": "niuniuche", "attribute": "toy"}
>>> print(json.dumps(data,indent=3))
{
   "age": 4,
   "name": "niuniuche",
   "attribute": "toy"
}
>>>

 

相关文章:

  • 2021-11-29
  • 2022-12-23
  • 2021-06-07
  • 2021-05-26
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2021-12-28
相关资源
相似解决方案