Python 官方文档:入门教程 => 点击学习
主文件: from ConfigParser import ConfigParser config = ConfigParser() config.read("test.xml") 函数使用: 1.读取配置文件 -read(filena
主文件:
- import ConfigParser
- import string, os, sys
- cf = ConfigParser.ConfigParser()
- cf.read("test.conf")
- # 返回所有的section
- s = cf.sections()
- print 'section:', s
- o = cf.options("db")
- print 'options:', o
- v = cf.items("db")
- print 'db:', v
- print '-'*60
- #可以按照类型读取出来
- db_host = cf.get("db", "db_host")
- db_port = cf.getint("db", "db_port")
- db_user = cf.get("db", "db_user")
- db_pass = cf.get("db", "db_pass")
- # 返回的是整型的
- threads = cf.getint("concurrent", "thread")
- processors = cf.getint("concurrent", "processor")
- print "db_host:", db_host
- print "db_port:", db_port
- print "db_user:", db_user
- print "db_pass:", db_pass
- print "thread:", threads
- print "processor:", processors
- #修改一个值,再写回去
- cf.set("db", "db_pass", "zhaowei")
- cf.write(open("test.conf", "w"))
--结束END--
本文标题: python ConfigParser模
本文链接: https://lsjlt.com/news/190008.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0