import configparser config = configparser.ConfigParser() config['DEFAULT'] = { 'ServerAliveInterval': '45', 'Compression': 'yes', 'CompressionLevel': '9' } config['bitbucket.org'] = {} config['bitbucket.org']['User'] = 'hg' config['topsecret.server.com'] = {} topsecret = config['topsecret.server.com'] topsecret['Port'] = '50022' topsecret['ForwardX11'] = 'no' config['DEFAULT']['ForwardX11'] = 'yes' with open('example.ini', 'w') as configfile: config.write(configfile)
import configparser config = configparser.ConfigParser() config.read('example.ini') print(config['bitbucket.org']['User']) # hg print(config['DEFAULT']['Compression']) # yesThe above code reads the `example.ini` file and retrieves specific settings from the configuration file. The package library used in these examples is configparser, which is a part of the standard Python library.