fromconfigparser Import Configparserdef write (): CP=configparser () cp[' One'] = { 'AA':'111', 'BB':'222'} cp[' Both'] =dict (CC='ZXL', DD='Hhu') cp['three'] ={} cp['three']['ee'] ='888'T= cp['three'] t['FF'] ='999'With Open ('Config','W') asF:cp.write (f) def read (): CP=configparser () # Print (cp.sections ()) Result= Cp.read ('Config') # Print (Cp.has_option (' One','AA') # Print (Cp.has_section ('three')) # forIinchCP: # Print (i) # forIinchcp[' Both']: # print (i) # print (Type (result), result) # print (Cp.sections ()) # Print (' One' inchCP) # Print (cp[' One']) # value= cp[' One']['AA'] # Print (type (value), value) # value= CP.Get(' One','AA') # Print (type (value), value) # value= Cp.getint (' One','AA') # Print (type (value), value) read () def delete (): CP=configparser () Read= Cp.read ('Config') cp.remove_section (' Both') cp.remove_option ('three','ee') with open ('Config2','W') asF:cp.write (f) # Delete () def update (): CP=Configparser () cp.read ('Config') CP.Set(' One','AA','Zhangsan') with open ('Config','W') asF:cp.write (f) # Update ()
Python's Configparser module