Share The iFile operation class implemented by Python

Source: Internet
Author: User
This article mainly introduces how to share the INI file operation class implemented by Python. This article provides the implementation code directly. if you need it, you can refer to the following class code:

# -*- coding:gbk -*-import ConfigParser, osclass 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.