zoukankan      html  css  js  c++  java
  • python之configParser模块读写配置文件

    借鉴:http://www.cnblogs.com/TankXiao/p/3038350.html

    configParser是python自带的模块,用来读写配置文件

    配置文件的格式:[]包含的叫section,section下有option=value这样的键值

    配置文件  test.conf

    [section1]

    name = tank

    age = 28

    [section2]

    ip = 127.0.0.1

    port = 8080

    python代码

    #-*- coding:UTF-8 -*-

    import configParser

    conf = configParser.configParser()

    conf.read("c:\tset.conf")

    #获取指定的section,指定的option的值

    name = conf.get("section1", "name")

    print name

    age = conf.get("section1", "age")

    print age

    #获取所有的section

    sections = conf.sections()

    print sections

    #写配置文件

    #更新指定的section,option的值

    conf.set("sections","port","8081")

    # 写入指定section, 增加新option的值
    conf.set("section2", "IEPort", "80")

    # 添加新的 section
    conf.add_section("new_section")
    conf.set("new_section", "new_option", "http://www.cnblogs.com/tankxiao")

  • 相关阅读:
    bzoj3809
    bzoj2038
    bzoj1113
    oralce 知识
    oracle 12c安装详细教程
    oracle 知识点
    oracle 面试题
    PLSQL Developer工具的使用
    使用net Manager工具配置远程连接oracle
    vnc安装
  • 原文地址:https://www.cnblogs.com/zzzidea/p/7214273.html
Copyright © 2011-2022 走看看