• ConfigParser模块,主要应用于对php.ini等格式的配置文件内容读取和生成。删改较少用


     *.ini配置文件样例 

    创建默认的文件样例

    读取文件内容

    read()

    configparser增删改查语法

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    [section1]
    k1 = v1
    k2:v2
      
    [section2]
    k1 = v1
     
    import ConfigParser
      
    config = ConfigParser.ConfigParser()
    config.read('i.cfg')
      
    # ########## 读 ##########
    #secs = config.sections()
    #print secs
    #options = config.options('group2')
    #print options
      
    #item_list = config.items('group2')
    #print item_list
      
    #val = config.get('group1','key')
    #val = config.getint('group1','key')
      
    # ########## 改写 ##########
    #sec = config.remove_section('group1')
    #config.write(open('i.cfg', "w"))
      
    #sec = config.has_section('wupeiqi')
    #sec = config.add_section('wupeiqi')
    #config.write(open('i.cfg', "w"))
      
      
    #config.set('group2','k1',11111)
    #config.write(open('i.cfg', "w"))
      
    #config.remove_option('group2','age')
    #config.write(open('i.cfg', "w"))
  • 相关阅读:
    初识Java内存结构
    eclipse的安装与配置
    关于android客户端使用ksoap2调用wcf(.svc)的总结
    ie下jpg不显示问题
    Android学习笔记(1)
    HTML标签语义化
    【转】android模拟机不能上网
    WCF IIS 寄宿问题
    C# 参数传递
    Wcf IIS 寄宿
  • 原文地址:https://www.cnblogs.com/zhangmingda/p/9132645.html
Copyright © 2020-2023  润新知