0x 01ini文件的格式
[student] //SECTION是一个节的名称 name = gumin //section下面是键值对的组合 sex = man birthday = 1990 [blonging] phone = iphone10s computer = thinkpad
0x02 ConfigParser模块
ConfigParser 是用来读取配置文件的模块,下面我们通过代码示例来看一下它是如何使用的
#-*-coding:utf-8-*-
import ConfigParser #引入ConfigParser模块
cfg = Config.Parser.ConfigParser #初始化ConfigParser
cfg.read("Config.ini") #导入测试的ini文件,参考0x00
cfg.section() #输出section列表
<img src="https://img-blog.youkuaiyun.com/20151025162245463" alt="" />
cfg.items('student') #输出student节下的所有键值对列表
<img src="https://img-blog.youkuaiyun.com/20151025162348165" alt="" />
cfg.options('student') #输出student节下所有key的值
<img src="https://img-blog.youkuaiyun.com/20151025164205070" alt="" />
cfg.get('student','name') #获取student节下的key值为name的value
<img src="https://img-blog.youkuaiyun.com/20151025164354609" alt="" />
cfg.set('student','name','gumin2') #修改name键对应的值,或者你新插入键值对,只要保证你的key是不重复的
cfg.remove_option('student','sex') #删除sex键
0x03 Config文件管理类
待补充