Python pattern for sharing configuration throughout application

You could just:

import config

and have a global config module


excerpts from my comments:

You can always add special rules for odd situations by just saying oddValue if isOddSituation() else config.normalValue.

If you want to have configuration modules be hierarchically subclassable (like my other answer describes), then you can represent a config as a class, or you can use the copy module and make a shallow copy and modify it, or you can use a “config dictionary”, e.g.:

import config as baseConfig
config = dict(baseConfig, overriddenValue=etc)

It doesn’t really matter too much which scope you’re in.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)