Keepin constants, configuration values, etc. in Python - dedicated module or what?

Chris Angelico rosuav at
Tue Sep 30 18:51:27 CEST 2014

On Wed, Oct 1, 2014 at 2:39 AM, Rustom Mody <rustompmody at> wrote:
>>     python - just keep config in the modules/classes, not easy to use
>>     at 'both ends' (home and remote), otherwise quite simple
> Can work at a trivial level.
> As soon as things get a bit larger data and code mixed up is a recipe for mess up.

True, but it's certainly possible to break out the config data into an
importable module that conceptually just provides constants.
Technically it's code, yes, but it'll normally be code that looks like
your standard "name = value" config file:

# docs for first option
# more docs
# examples
# etcetera
first_option =123

# docs for second option
second_option = 234

Is that Python code, or is it a sectionless INI file, or what? There's
no difference. And you get expressions for free - simple stuff like
"7*24*60*60" to represent the number of seconds in a week (for people
who aren't intimately familiar with 604800), or calculations relative
to previous data, or whatever. Sometimes it's helpful to have just a
little code in your data.


More information about the Python-list mailing list