Use configParser module in Python.

Utshab Kumar Ghosh
1 min readJan 31, 2021

Config files with extension .ini are very useful for different purposes, like:

  • storing app configuration
  • hiding sensitive data

Today we will learn the basics of creating those very config files, using them with configParser module which comes as a built-in package in Python. So, let’s dive in!

At first, we need to create a config.ini file. That will be something like this:

config.ini

The data can be divided into sections. Here are 2 sections([settings] & [aws]) in this code snippet. The values assigned in the variable will be stored as strings. So now, it’s time to access those values. For that, we go to a (say) config_scripts.py file and write something like this:

config_scripts.py

We can also write into config.ini file from the config_scripts.py file. How?

Running this code will show one more section(i.e. 3 instead of 2) which was added dynamically in the config.ini file. So it will give an output like:

Sections: ["settings", "aws", "more"]

So these are some chunks I know. Please share with me, if you know something more interesting or necessary. Please let me know if anything is not working or discuss my mistakes without any hesitations. Tada!

References:

  1. https://docs.python.org/3/library/configparser.html
  2. Image is taken from: https://www.youtube.com/watch?app=desktop&v=jBwfq6UMxkY

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Utshab Kumar Ghosh
Utshab Kumar Ghosh

Written by Utshab Kumar Ghosh

Passionate about Python, Image Processing, Computer Vision, Data Science, Machine Learning, and Deep Learning.

No responses yet

Write a response