Module One, Configparser
== V3
1. Get all nodes
Import= configparser. Configparser () config.read ('settings', encoding='utf-8' = Config.sections ()print (res)
2. Gets all the key-value pairs under the specified node
Import= configparser. Configparser () config.read ('settings', encoding='utf-8' = Config.items ('section1')print (res)
3, get all the keys under the node
Import= configparser. Configparser () config.read ('settings', encoding='utf-8' = Config.options ('section1')print (res)
4. Gets the value of the specified key under the specified node
Importconfigparser config=Configparser. Configparser () Config.read ('Settings', encoding='Utf-8') v= Config.get ('Section1','K1')#v = config.getint (' Section1 ', ' K1 ')#v = config.getfloat (' Section1 ', ' K1 ')#v = config.getboolean (' Section1 ', ' K1 ') Print(v)
5. Check, delete, add nodes
Importconfigparser config=Configparser. Configparser () Config.read ('Settings', encoding='Utf-8') #CheckHas_sec = Config.has_section ('Section1')Print(has_sec)#Adding nodesConfig.add_section ("sec_1") config.write (open ('Settings','W')) #Delete a nodeConfig.remove_section ("sec_1") config.write (open ('Settings','W'))
6. Check, delete, set the key value pairs within the specified group
Importconfigparser config=Configparser. Configparser () Config.read ('Settings', encoding='Utf-8') #Checkhas_opt = Config.has_option ('Section1','K1')Print(has_opt)#DeleteConfig.remove_option ('Section1','K1') config.write (open ('Settings','W')) #SetConfig.set ('Section1','K10',"123") config.write (open ('Settings','W'))
Python Module Class 2 preliminary