parse config file in python
in python, you may need to parse the config file sometime in your work. for example let the user config the app or server. you need to write config file like .ini or xml file.
this article will show you how to use simple .ini file and parse it using python.
there are library to help, before we start to use the library, we should know a little about the config file.
when using the library ConfigParser, there are some method may confuse you. something like: options, sections.
- options: items under the section
- section: this will appear in .ini file which surround with []
we start with this simple config file:
now I will show you what’s the section and option:
you will see the output here:
get and value of the option:
set the value of the option:
save the config file at last:
to find more information about the usage, you can forward to the doc.