configparser模块
1 import configparser 2 3 config = configparser.ConfigParser() 4 config['DEFAULT'] = { 5 'ServerAliveInterval': 45, 6 'Compression': 'yes', 7 'CompressionLevel': 9, 8 'ForwardX11': 'yes' 9 } 10 config['bit'] = { 11 'bitbucket': 'hg', 12 "User": 'nihoa' 13 } 14 config['SERVER'] = { 15 'PORT': 8080, 16 'PASSWD': 2663 17 } 18 with open('aa.config', 'w') as f: 19 config.write(f) 20 # 增删改查 21 # ---------------------查 22 config = configparser.ConfigParser() # 创建对象 23 config.read('aa.config') # 将文件传进对象 24 print(config.sections()) # 打印文件的各个部分 25 print('ok' if 'bit' in config.sections() else 'no') #