import re
re.findall("(?:abc)+","abcabcabc")
--->['abcabcabc']
import configparser
config = configparser.ConfigParser()   #创建配置文件,config = {}相当于一个字典

config["default"] = {'ServerAliveInterval':45,
                     'Compression':'yes',
                     'CompressionLevel':'9'}

config['bitbucket.org'] = {}
config['bitbucket.org']['User'] = 'zsz'

config['topsecret.server.com'] = {}
topsecret = config['topsecret.server.com']
topsecret['Host Port'] = '50022'
topsecret['ForwardX11'] = 'no'

with open('example.ini','w') as f:
    config.write(f)
f.close()
#----------------------------------------------增删改查------------------------------------------------------------
#
config = configparser.ConfigParser()
config.read('example.ini')
print(config.sections()) #得到所有的块
--->['default', 'bitbucket.org', 'topsecret.server.com']
print('bytebong.com' in config) #判断块中是否有bytebong.com
--->False
print(config['bitbucket.org']['User'])
--->zsz
print(config['default']['compression'])
--->yes
print(config['topsecret.server.com']['forwardx11'])
--->no
for key in config['bitbucket.org']: #取'bitbucket.org'下所有的键 print(key)
--->user
print(config.options('default')) #取键
--->['serveraliveinterval', 'compression', 'compressionlevel']
print(config.items('default')) #得到块下的键值对
--->[('serveraliveinterval', '45'), ('compression', 'yes'), ('compressionlevel', '9')]
print(config.get('default','compression')) #得到对应键的值
--->yes

#删,改,查 config.add_section('yuan') #增加块 config.set('yuan','k1','11111') #添加键值对 config.remove_section('topsecret.server.com') #删除块 config.remove_option('default','compression') #删除块下的键值对 config.write(open('example.ini','w')) #这么写不用关闭文件