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)
相关推荐
CloudXli 2020-04-20
Cyuhong 2019-04-24
Ping 2016-11-17
youandme 2018-06-09
PythonGCS 2015-05-28
小金屋 2019-04-16
逍遥友 2020-11-20
olyqcool 2020-07-19
cunxinwenwu的IT 2020-05-28
JF0 2020-05-08
cyhgogogo 2020-05-03
vshacker 2020-01-09
igogo00 2015-07-28
迈克揉索芙特 2008-09-07
如狼 2014-04-04
技术渣 2014-11-14
wqcong 2016-02-16
xiaopc 2016-04-09
Trisyp 2016-02-17