Python Notes and Examples
← prev | next →     Top-level ToC     /config-files.html     (printable version)

There are a number of options.


You can create a module containing a hashmap that can serve as a config file:

cd my-proj
chmod +x

where contains:

config = {
    'name': 'ringo',
    'speed': 13,
    'radius': 5,

and contains:

#!/usr/bin/env python3

import config as c

print('speed is', c.config['speed'])

2 Customary-style config files

See the docs for configparser.

from configparser import ConfigParser
config = ConfigParser()'foo.ini')

That gives you something like a map of maps. That is, you can index into it like a map, but you can’t just print the whole thing out.