Python文件配置configParser使用
来源:互联网 发布:天界法宝升阶数据 编辑:程序博客网 时间:2024/04/30 19:12
<pre name="code" class="python"># -*- coding:gb2312 -*-import ConfigParserclass student_info(object): '''1.dump ini2.del section3.del item4.modify item5.add section6.save modify''' def __init__(self, recordfile): # 文件名字 self.logfile = recordfile self.cfg = ConfigParser.ConfigParser() # 将文件load到cfg中 def cfg_load(self): self.cfg.read(self.logfile) # 将写入内存中的内容显示出来(这些操作并不是在我们磁盘文件中的修改) def cfg_dump(self): se_list = self.cfg.sections() print "===================>" for se in se_list: print se # se相当于一个字典 print self.cfg.items(se) print "<==================" # 删除条目 def delete_item(self, section, key): self.cfg.remove_option(section, key) # 删除section(课程) def delete_section(self, section): self.cfg.remove_section(section) # 添加一个section def add_section(self, section): self.cfg.add_section(section) # 添加和修改条目 def set_item(self, section, key, value): self.cfg.set(section, key, value) def save(self): fp = open(self.logfile, 'w') self.cfg.write(fp) fp.close()if __name__ == '__main__': info = student_info('liuyc.txt') info.cfg_load() info.cfg_dump() info.add_section('yuwen') # 第二次需要注释掉 info.set_item('yuwen', 'liuyc', '88') info.set_item('yuwen', 'xiongda', '20') info.set_item('yuwen', 'xionger', [1,2,3,4,5]) info.cfg_dump() info.save()# '''# ini配置文件格式:# 节:[session]# 参数(键=值) name=value# '''
0 0
- Python文件配置configParser使用
- python ConfigParser配置读写
- Python读写配置configparser
- Python ConfigParser的使用
- Python ConfigParser的使用
- Python ConfigParser的使用
- python ConfigParser使用
- Python ConfigParser的使用
- Python ConfigParser的使用
- Python ConfigParser的使用
- Python ConfigParser使用
- python 中configparser的使用
- python中ConfigParser模块使用
- 嵌入式 python之ConfigParser配置解析模块
- Python 解析配置模块之ConfigParser详解
- python ConfigParser 参数化配置 学习笔记
- Python 解析配置模块之ConfigParser详解
- Python 解析配置模块之ConfigParser详解
- java流与文件——流
- linux Centos6.5 安装 jdk1.6
- STL_算法_查找算法(adjacent_find)
- linux 下C调用Python 模块
- Windows7系统下更改安装包的兼容模式离线安装.Net FrameWork3.5
- Python文件配置configParser使用
- 一次使用Eclipse Memory Analyzer分析Tomcat内存溢出
- 如何通过Request获取用户真实IP
- Android实训案例(二)——Android下的CMD命令之关机重启以及重启recovery
- 待整理(平台)
- 多线程断点续传
- NYoj46 最少乘法次数
- 2015年年中总结暨2016年全年计划 ----#天生骄傲#
- js(jQuery)获取时间的方法及常用时间类