玩蛇网提供最新Python编程技术信息以及Python资源下载!

想用pyhton语言完成编写toml文件求个思路或是方法

请问哪位大神知道如何利用python编写toml文件?谢谢

使用toml包

它的使用类似json.dumps json.loads

介绍:
http://mlworks.cn/posts/intro...

比如使用pipenv的配置文件为

[dev-packages]
pytest = "*"
sphinx = "*"

[packages]
click = "*"
crayons = "*"
toml = "*"
"delegator.py" = ">=0.0.6"
requests = ">=2.4.0"
requirements-parser = "*"
parse = "*"
pipfile = "==0.0.1"
click-completion = "*"
"backports.shutil-get-terminal-size" = "*"
pew = ">=0.1.26"
blindspin = "*"

[requires]
python_version = "2.7"

操用

In [5]: toml.load(open('Pipfile'))
Out[5]: 
{u'dev-packages': {u'pytest': u'*', u'sphinx': u'*'},
 u'packages': {u'backports.shutil-get-terminal-size': u'*',
  u'blindspin': u'*',
  u'click': u'*',
  u'click-completion': u'*',
  u'crayons': u'*',
  u'delegator.py': u'>=0.0.6',
  u'parse': u'*',
  u'pew': u'>=0.1.26',
  u'pipfile': u'==0.0.1',
  u'requests': u'>=2.4.0',
  u'requirements-parser': u'*',
  u'toml': u'*'},
 u'requires': {u'python_version': u'2.7'}}

In [7]: toml.dumps(data)
Out[7]: u'[dev-packages]\npytest = "*"\nsphinx = "*"\n[packages]\ncrayons = "*"\nrequirements-parser = "*"\n"backports.shutil-get-terminal-size" = "*"\n"delegator.py" = ">=0.0.6"\nblindspin = "*"\npew = ">=0.1.26"\nparse = "*"\ntoml = "*"\npipfile = "==0.0.1"\nrequests = ">=2.4.0"\nclick-completion = "*"\nclick = "*"\n[requires]\npython_version = "2.7"\n'

玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd14090.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年05月22日 - 09时04分14秒 发布自玩蛇网

您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容
我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules