RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Python中怎么操作ini文件

Python中怎么操作ini文件,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

创新互联公司专注于企业网络营销推广、网站重做改版、马关网站定制设计、自适应品牌网站建设、H5网站设计商城系统网站开发、集团公司官网建设、外贸营销网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为马关等各大城市提供网站开发制作服务。

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中怎么操作ini文件的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


本文题目:Python中怎么操作ini文件
新闻来源:http://sczitong.cn/article/pgosod.html