博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ConfigParser模块
阅读量:4546 次
发布时间:2019-06-08

本文共 1192 字,大约阅读时间需要 3 分钟。

 

用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser。

来看一个好多软件的常见文档格式如下

 

[DEFAULT] serveraliveinterval = 45 compression = yes compressionlevel = 9 forwardx11 = yes [bitbucket.org] user = hg [topsecret.server.com] host port = 50022 forwardx11 = no #创建
#!/usr/bin/env python import configparser #ConfigParser config = configparser.ConfigParser() config["DEFAULT"] = {'ServerAliveInterval': '45',                      'Compression': 'yes',                      'CompressionLevel': '9'} config['bitbucket.org'] = {} config['bitbucket.org']['User'] = 'hg' config['topsecret.server.com'] = {} config['topsecret.server.com'] config['topsecret.server.com']['Host Port'] = '50022'  # mutates the parser config['topsecret.server.com']['ForwardX11'] = 'no'  # same here config['DEFAULT']['ForwardX11'] = 'yes' with open('example.ini', 'w') as configfile:     config.write(configfile) #读写
#!/usr/bin/env python import configparser conf = configparser.ConfigParser() conf.read("example.ini") print(conf.defaults()) print(conf['bitbucket.org']['user']) #print(conf.sections()) sec = conf.remove_section('bitbucket.org') conf.write(open('example.ini', "w"))
 

转载于:https://www.cnblogs.com/rongye/p/9942803.html

你可能感兴趣的文章
10条建议帮助你创建更好的jQuery插件
查看>>
setPreferredSize和setSize的区别及用法
查看>>
Python简介及编码
查看>>
[转]Android:Layout_weight的深刻理解
查看>>
监听键盘弹出 隐藏
查看>>
iOS开发 - NSBundle, NSDevice, NSLocale
查看>>
innerHtml安全问题
查看>>
UVA 11992,。。。伪-二维线段树
查看>>
[原创]通过函数指针实现事件消息处理
查看>>
IE下JS保存图片
查看>>
293.Flip Game
查看>>
uvaLive5713 次小生成树
查看>>
mysql原生语句基础知识
查看>>
Ubuntu11搭建QT开发环境
查看>>
深度学习样本不均衡问题解决
查看>>
Servlet中Web.xml的配置详解
查看>>
RabbitMQ headers Exchange
查看>>
硬件产品测试
查看>>
nmon for linux
查看>>
H5 EventSource 实现web页面推送功能demo
查看>>