= = = 9 = = = 50022= no
With one of the above configuration documents, he is required to read, and delete and modify the operation.
#@File: 4.9configparser module. PY#@Software: PycharmImportconfigparserconf=Configparser. Configparser () Conf.read ('Cofing.ini')Print(conf.default_section)#Print file header defaultPrint(Conf.sections ())#List of configuration items in the Print configuration file#1. CheckPrint(List (Conf.keys ()))#check all keys .Print(List (conf['bitbucket.org']))#value under [' bitbucket.org '] forKvinchconf['topsecret.server.com'].items ():Print(k, v)#output The following values-this means#the value of conf[' topsecret.server.com '] also contains the value of the default above#facilitates data reuse#Port 50022#forwardx11 No#Serveraliveinterval#Compression Yes#CompressionLevel 9#in to determine if the parameter is in Confif 'User' inchconf['bitbucket.org']: Print('inch')
#@File: 4.9.1configpasrser module contact. PY#@Software: PycharmImportconfigparserconf=Configparser. Configparser () Conf.read ('Conf_test.ini')Print(conf['group1'])Print(conf['group1']['K2'])#2. IncreaseConf.add_section ('Group3') conf['Group3'][' Age'] = str (22) conf.write (open ('Conf_test1.ini','W'))#3. DeleteConf.remove_option ('group1','K2') conf.write (open ('Conf_test2.ini','W'))
python-configuration file Processing Configpasser module