''' config.cfg [whatever] key=qwerertyertywert2345 secret=sadfgwertgrtujdfgh ''' from configparser import ConfigParser config = ConfigParser() config.read('config.cfg') my_key = config['whatever']['key'] my_secret = config['whatever']['secret']
Here is what the above code is Doing:
1. Importing the ConfigParser class from the configparser module.
2. Creating an instance of the ConfigParser class.
3. Calling the read() method on the config object. This reads the config.cfg file into memory.
4. Using the config object to access the key and secret values.