Python 鏍煎紡鍖栨墦鍗?dict銆乯son 鏁版嵁
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 鏍煎紡鍖栨墦鍗?dict銆乯son 鏁版嵁相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/info' title='info'>info 鎵撳嵃 import asc ensure int inf printer
1.浣跨敤瀹樻柟妯″潡 pprint 鏍煎紡鍖栨墦鍗?dict 鏁版嵁
import pprint # indent锛氬畾涔夊嚑涓┖鏍肩殑缂╄繘 pp = pprint.PrettyPrinter(indent=2) info = dict(age=50, money=0, a=1, b=dict(h=7, i=8, j=9), c=2, d=3, e=4, f=5, g=6) pp.pprint(info)
杈撳嚭锛?/p>
{ 鈥?/span>a鈥?/span>: 1,
鈥?/span>age鈥?/span>: 50,
鈥?/span>b鈥?/span>: {鈥?/span>h鈥?/span>: 7, 鈥?/span>i鈥?/span>: 8, 鈥?/span>j鈥?/span>: 9},
鈥?/span>c鈥?/span>: 2,
鈥?/span>d鈥?/span>: 3,
鈥?/span>e鈥?/span>: 4,
鈥?/span>f鈥?/span>: 5,
鈥?/span>g鈥?/span>: 6,
鈥?/span>money鈥?/span>: 0}
2.鏍煎紡鍖栨墦鍗?json 鏍煎紡鐨勬暟鎹?/p>
import json info = dict(age=50, money=0, a=1, b=dict(h=7, i=8, j=9), c=2, d=3, e=4, f=5, g=6) # indent锛氬畾涔夊嚑涓┖鏍肩殑缂╄繘 # separators锛氬畾涔?"," ":" 鍓嶅悗鐨勭┖鏍兼暟閲?/span> print(json.dumps(info, indent=1, separators=(鈥?/span>, 鈥?/span>, 鈥?/span>: 鈥?/span>), ensure_ascii=False))
杈撳嚭锛?/p>
{ "age": 50, "money": 0, "a": 1, "b": { "h": 7, "i": 8, "j": 9 }, "c": 2, "d": 3, "e": 4, "f": 5, "g": 6 }
以上是关于Python 鏍煎紡鍖栨墦鍗?dict銆乯son 鏁版嵁的主要内容,如果未能解决你的问题,请参考以下文章
Python璇诲彇mysql鏁版嵁锛岃浆涓篋ataFrame鏍煎紡骞舵牴鎹師TABLE涓殑COLUMNS鎸囧畾columns锛宨ndex