圆月山庄资源网 Design By www.vgjia.com

类代码:

# -*- 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文件操作类

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com