Python实现的ini文件操作类分享,
Python实现的ini文件操作类分享,
类代码:
# -*- coding:gbk -*- import ConfigParser, os class INIFILE: def __init__(self, filename): self.filename = filename self.initflag = False self.cfg = None self.readhandle = None self.writehandle = None def Init(self): self.cfg = ConfigParser.ConfigParser() try: self.readhandle = open(self.filename, 'r') self.cfg.readfp(self.readhandle) self.writehandle = open(self.filename, 'w') self.initflag = True except: self.initflag = False return self.initflag def UnInit(self): if self.initflag: self.readhandle.close() self.writehandle.closse() def GetValue(self, Section, Key, Default = ""): try: value = self.cfg.get(Section, Key) except: value = Default return value def SetValue(self, Section, Key, Value): try: self.cfg.set(Section, Key, Value) except: self.cfg.add_section(Section) self.cfg.set(Section, Key, Value) self.cfg.write(self.writehandle)
相关内容
- Python实现的tab文件操作类分享,
- Python使用py2exe打包程序介绍,pythonpy2exe
- Python常用模块介绍,python模块
- Python实现的下载8000首儿歌的代码分享,python8000首
- Python和perl实现批量对目录下电子书文件重命名的代码分
- Python pickle类库介绍(对象序列化和反序列化),pytho
- Python multiprocessing.Manager介绍和实例(进程间共享数据)
- Python多进程同步Lock、Semaphore、Event实例,pythonsemaphore
- Python多进程通信Queue、Pipe、Value、Array实例,pythonqueue
- python多进程操作实例,python进程实例
评论关闭