Python实现的ini文件操作类分享

Doris ·
更新时间:2024-09-20
· 549 次阅读

类代码:

# -*- 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读写ini文件的方法Python读取ini文件、操作mysql、发送邮件实例Python中使用ConfigParser解析ini配置文件实例python读写ini文件示例(python读写文件)python读写ini配置文件方法实例分析



ini ini文件 Python

需要 登录 后方可回复, 如果你还没有账号请 注册新账号