推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
habin
V2EX  ›  Python

Python json.dump 输出格式求助

  •  
  •   habin · Aug 6, 2019 · 3332 views
    This topic created in 2617 days ago, the information mentioned may be changed or developed.
    json.dump(dict, f,separators=(',',':'))输出格式为:
    {"AAPP":["0","0","0","0","0","0","0","0"],"AAPP_TD":["0","0","0","0","0","0","0","0"]}

    json.dump(dict, f,indent=0,separators=(',',':'))输出格式为:
    {
    "AAPP":[
    "0",
    "0",
    "0",
    "0",
    "0",
    "0",
    "0",
    "0"
    ],
    "AAPP_TD":[
    "0",
    "0",
    "0",
    "0",
    "0",
    "0",
    "0",
    "0"
    ]
    }

    请问如果操作才能达到以下想要的格式为,:
    {
    "AAPP":["0","0","0","0","0","0","0","0"],
    "AAPP_TD":["0","0","0","0","0","0","0","0"]
    }
    2 replies  •  2019-08-06 10:32:05 +08:00
    est
        1
    est  
       Aug 6, 2019   ❤️ 1
    一个 key-value 占一行? separators=(',\n' 这样?
    luhuisicnu
        2
    luhuisicnu  
       Aug 6, 2019   ❤️ 1
    调试 indent 这个参数
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   753 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 21:39 · PVG 05:39 · LAX 14:39 · JFK 17:39
    ♥ Do have faith in what you're doing.