V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2019-08-06 09:53:24 +08:00 · 2272 次点击
    这是一个创建于 1938 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2019-08-06 10:32:05 +08:00
    est
        1
    est  
       2019-08-06 10:23:00 +08:00   ❤️ 1
    一个 key-value 占一行? separators=(',\n' 这样?
    luhuisicnu
        2
    luhuisicnu  
       2019-08-06 10:32:05 +08:00   ❤️ 1
    调试 indent 这个参数
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1257 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 18:11 · PVG 02:11 · LAX 10:11 · JFK 13:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.