configParser module
Posted plkm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了configParser module相关的知识,希望对你有一定的参考价值。
# __author: # date:2020/2/25 import configparser config = configparser.ConfigParser() config[‘DEFAULT‘] = {‘ServerAliveInterval‘ : ‘45‘, "Compression" : ‘yes‘, "CompressionLevel" : "9" } config[‘bitbucket.org‘] = {} config[‘bitbucket.org‘]["User"] = ‘New Comer‘ config[‘topsecrect.server.com‘] = {} topsecret = config[‘topsecrect.server.com‘] topsecret[‘Host Port‘] = ‘50022‘ topsecret[‘ForWardX11‘] = ‘no‘ config[‘DEFAULT‘][‘ForWardX11‘] = ‘yes‘ with open(‘config_example.ini‘, ‘w‘) as configfile: config.write(configfile) # config.read(‘config_example.ini‘) print(config.sections()) print(config[‘DEFAULT‘]) for key in config[‘DEFAULT‘]: print(key,‘:‘,config[‘DEFAULT‘][key]) print(config[config.sections()[1]]) print(config[config.sections()[1]][‘Host Port‘]) config1 = configparser.ConfigParser() print(config1.sections()) config1.read(‘config_example.ini‘) print(config1.sections()) print(config1.options(‘topsecrect.server.com‘)) print(config1.get(‘DEFAULT‘,‘ForWardX11‘)) config1.write(open(‘config_example2.ini‘, ‘w‘)) config1.add_section(‘New Section‘) config1.set(‘New Section‘,‘New Option‘,‘New Value‘) config1.write(open(‘config_example2.ini‘, ‘w‘)) print(config1.sections()) for i in config1.sections(): print(config1.options(i)) config1.remove_option(‘New Section‘,‘New Option‘) config1.remove_section(‘New Section‘) config1.set(‘bitbucket.org‘,‘User‘,‘My Name‘) config1.write(open(‘config_example2.ini‘,‘w‘))
[‘bitbucket.org‘, ‘topsecrect.server.com‘] <Section: DEFAULT> serveraliveinterval : 45 compression : yes compressionlevel : 9 forwardx11 : yes <Section: topsecrect.server.com> 50022 [] [‘bitbucket.org‘, ‘topsecrect.server.com‘] [‘host port‘, ‘forwardx11‘, ‘serveraliveinterval‘, ‘compression‘, ‘compressionlevel‘] yes [‘bitbucket.org‘, ‘topsecrect.server.com‘, ‘New Section‘] [‘user‘, ‘serveraliveinterval‘, ‘compression‘, ‘compressionlevel‘, ‘forwardx11‘] [‘host port‘, ‘forwardx11‘, ‘serveraliveinterval‘, ‘compression‘, ‘compressionlevel‘] [‘new option‘, ‘serveraliveinterval‘, ‘compression‘, ‘compressionlevel‘, ‘forwardx11‘] Process finished with exit code 0
以上是关于configParser module的主要内容,如果未能解决你的问题,请参考以下文章
在python3中安装mysql扩展,No module named 'ConfigParser'
在python3中安装mysql扩展,No module named 'ConfigParser'
ImportError: No module named 'ConfigParser'
Ubuntu安装Sqlite报错:No module named 'ConfigParser'
[react] Module not found: Can't resolve 'schedule' in 'C:Usersadcaldvmtn7myapp (代码片段