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

Rustom Mody rustompmody at
Tue Sep 30 19:31:01 CEST 2014

On Tuesday, September 30, 2014 10:46:21 PM UTC+5:30, Chris Angelico wrote:
> On Wed, Oct 1, 2014 at 3:01 AM, Rustom Mody  wrote:
> >> 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.
> > Not free at all. Power of code means cost of code
> > See

> It's free once you've already decided (for other reasons) to make your
> config file use Python syntax, at which point you've already paid the
> cost of code. But you're quite right, allowing code does have costs.
> Most notably, you have to quote your strings; although the direct
> benefits you get (line continuation, unambiguous handling of
> leading/trailing spaces, etc) may outweigh that on their own.

> > I'd reiterate though what I first said: In this case its probably
> > ok if the code (=data) does not cross trivial limits

> I'd agree, where "trivial limits" is defined by each individual item.
> Going with straight Python code is fine for huge projects with long
> config files, as long as each config entry is itself simple. You even
> get a form of #include: "from otherfile import *".

Well in programming we sometimes use strict/formal methods and sometimes more

In this case using configparser or pyyaml or whatever means that the config
file's syntax is rigorously fixed by that library

On the other hand if you impose a convention: Constants file-module has
NOTHING but constants, thats a non-formal convention and thats ok. 

If however you mix it up with other (real) code, you'll get a bloody mess.
This kind of stuff "7*24*60*60" is borderline and in my experience
its a slippery slope that ends up being more trouble than its worth.

Experience being emacs where because in lisp code and data are
the same, all kinds of design messes are perpetrated

More information about the Python-list mailing list