小技巧 Python打印有格式的字典dict、json数据
import json
import pprint
hero_dict = {
"heroId": "1",
"name": "黑暗之女",
"alias": "Annie",
"title": "安妮",
"roles": [],
"isWeekFree": "0",
"attack": "2",
"defense": "3",
"magic": "10",
"difficulty": "6",
"selectAudio": "https://game.gtimg.cn/images/lol/act/img/vo/choose/1.ogg",
"banAudio": "https://game.gtimg.cn/images/lol/act/img/vo/ban/1.ogg",
"isARAMweekfree": "0",
"ispermanentweekfree": "0",
"changeLabel": "无改动",
"goldPrice": "4800",
"couponPrice": "2000",
"camp": "",
"campId": "",
"keywords": "安妮,黑暗之女,火女,Annie,anni,heianzhinv,huonv,an,hazn,hn",
"other": {
"a": 1,
"b": 2
}
}
print(hero_dict)
print(json.dumps(hero_dict, indent=4))
pprint.pprint(hero_dict, width=2)