• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python读写ini配置文件方法实例分析

python读写ini配置文件方法实例分析

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python读取ini,python读取ini文件,python 解析ini,python解析ini文件,python ini等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了python读写ini配置文件方法。分享给大家供大家参考。具体实现方法如下:

import ConfigParser
import os
class ReadWriteConfFile:
  currentDir=os.path.dirname(__file__) 
  filepath=currentDir+os.path.sep+"inetMsgConfigure.ini"
  @staticmethod
  def getConfigParser():
    cf=ConfigParser.ConfigParser()
    cf.read(ReadWriteConfFile.filepath)
    return cf
  @staticmethod
  def writeConfigParser(cf):
    f=open(ReadWriteConfFile.filepath,"w");      
    cf.write(f)
    f.close();
  @staticmethod
  def getSectionValue(section,key):
    cf=ReadWriteConfFile.getConfigParser()
    return cf.get(section, key)
  @staticmethod
  def addSection(section):
    cf=ReadWriteConfFile.getConfigParser()
    allSections=cf.sections()
    if section in allSections:
      return
    else:
      cf.add_section(section)
      ReadWriteConfFile.writeConfigParser(cf)
  @staticmethod
  def setSectionValue(section,key,value):
    cf=ReadWriteConfFile.getConfigParser()
    cf.set(section, key, value)
    ReadWriteConfFile.writeConfigParser(cf)
if __name__ == '__main__':
  ReadWriteConfFile.addSection( 'messages')
  ReadWriteConfFile.setSectionValue( 'messages','name','sophia')
  x=ReadWriteConfFile.getSectionValue( 'messages','1000')
  print x

</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • python读写ini配置文件方法实例分析
  • Python读写ini文件的方法
  • Python读写ini文件的方法
  • Python读取ini文件、操作mysql、发送邮件实例
  • Python实现的ini文件操作类分享
  • Python实现的ini文件操作类分享
  • python读写ini文件示例(python读写文件)

相关文章

  • python 的列表遍历删除实现代码
  • python使用rabbitmq实现网络爬虫示例
  • python 控制语句
  • Linux下使用python调用top命令获得CPU利用率
  • Python中函数的参数定义和可变参数用法实例分析
  • Python解决鸡兔同笼问题的方法
  • Python的dict字典结构操作方法学习笔记
  • Python 爬虫学习笔记之正则表达式
  • 学习python之编写简单乘法口诀表实现代码
  • videocapture库制作python视频高速传输程序

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 玩转python爬虫之爬取糗事百科段子
    • Python中的生成器和yield详细介绍
    • Python 面向对象 成员的访问约束
    • Python标准库之Sys模块使用详解
    • python3.5 + PyQt5 +Eric6 实现的一个计算器代码
    • python 捕获shell脚本的输出结果实例
    • python subprocess 杀掉全部派生的子进程方法
    • netbeans7安装python插件的方法图解
    • python实现查询苹果手机维修进度
    • python从入门到精通(DAY 2)

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有