• Python基础18模块-configerparse模块


    1.congfigerparse简单应用

     1 import configparser
     2 config = configparser.ConfigParser()
     3 #
     4 config['bitbucket.org'] = {}
     5 config['bitbucket.org']['User'] = 'hg'
     6 config['topsecret.server.com'] = {}
     7 topsecret = config['topsecret.server.com']
     8 topsecret['Host Port'] = '5022'
     9 topsecret['ForwardX11'] = 'no'
    10 config['DEFAULT']['ForwardX11'] = 'yes'
    11 with open('example.ini','w') as f:
    12     config.write(f)
    13 config.read('example.ini')
    14 #读,定义在DEFAULT里的东西会默认读出来
    15 for key in config['bitbucket.org']:
    16     print(key)
    17 print(config.options('bitbucket.org'))
    18 print(config.items('bitbucket.org'))
    19 #增加
    20 config.add_section('yuan')
    21 config.set('bitbucket.org','k1','11111')
    22 #删除
    23 config.remove_section('topsecret.server.com')
    24 config.remove_option('bitbucket.org','User')
    25 config.write(open('example.ini','w'))
  • 相关阅读:
    将字符数组写到字符串
    两种比较不错的密码修改方案
    数组的应用 结构类型 使用深复制和浅复制 显示员工信息
    字符串处理技巧
    uva 1339
    11039
    uva 11636
    Uva401Palindromes
    poj2524-Ubiquitous Religions
    Poj1611The Suspects
  • 原文地址:https://www.cnblogs.com/josie930813/p/9835413.html
Copyright © 2020-2023  润新知