Python中读写配置文件的方法-创新互联
创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!
创新互联公司专注于广安企业网站建设,成都响应式网站建设,商城系统网站开发。广安网站建设公司,为广安等地区提供建站服务。全流程按需定制开发,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务这篇文章主要介绍Python中读写配置文件的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
读文件
代码如下:
from configobj import ConfigObj config = ConfigObj(filename) # value1 = config['keyword1'] value2 = config['keyword2'] # section1 = config['section1'] value3 = section1['keyword3'] value4 = section1['keyword4'] # # you could also write value3 = config['section1']['keyword3'] value4 = config['section1']['keyword4']
写文件
代码如下:
from configobj import ConfigObj config = ConfigObj() config.filename = filename # config['keyword1'] = value1 config['keyword2'] = value2 # config['section1'] = {} config['section1']['keyword3'] = value3 config['section1']['keyword4'] = value4 # section2 = { 'keyword5': value5, 'keyword6': value6, 'sub-section': { 'keyword7': value7 } } config['section2'] = section2 # config['section3'] = {} config['section3']['keyword 8'] = [value8, value9, value10] config['section3']['keyword 9'] = [value11, value12, value13] # config.write()
以上是Python中读写配置文件的方法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联-成都网站建设公司行业资讯频道!
网站题目:Python中读写配置文件的方法-创新互联
分享地址:http://ybzwz.com/article/dhigje.html