ConfigParser Import
CP = configparser.ConfigParser () # instantiated
cp.read ( "config.conf", encoding = "utf-8") # reads the configuration file, to read a plurality of profiles allows, by listing
section # [] get all the inside section
f = cp.sections ()
Print (f)
Print ( "--------------------")
# the option option to access the section for the student All options under
v = cp.options ( "Student")
Print (v)
Print ( "--------------------")
# items, take each section all keys under the
kv = cp.items ( "Student")
Print (kv)
Print ( "--------------------")
# get a specific value
kv = cp.get ( "student", "class") # are read out of the string
Print (kV)
Print ( "------------------ - ")
# Get all the profile values
# integer reads data
kv = cp.getint ( "student", "class") # read out is an integer
Print (kv)
Print ( "--------------------")
# Float getFloat
# Boolean value getBoolean
# pretending to list eval, eval how to express what would turn into
python configuration file read configparser
Guess you like
Origin www.cnblogs.com/yago/p/11443810.html
Recommended
Ranking