Parsing ini files

PostImage

Photo by Sincerely Media on Unsplash

Good afternoon, casual reader.

For one project, it was required to get the value of a variable from an ini file.

And it seems like the solution is simple, a one-line script like:

grep dbname db.conf | awk -F '=' '{ print $2 }'

But what if there are several values in different sections? Then a one-line script will not work anymore.

Search for a solution for linux gave no results :(, although maybe I'm just lazy and have not looked through all the search results.

The decision was made quickly, we take Python and the configparser package. Result ini-file.