Avoiding `exec', how to? [and why usie it in the first place?]

François Pinard pinard at iro.umontreal.ca
Fri May 31 09:00:29 EDT 2002


[Steve Holden]

> > The goal here is to initialise one global variable per item in DEFS,
> > preserving the item name and value in each.

> I was hoping we might see some discussion of *why* you want to do this.

Oh!  I was merging two modules into this one which is widely imported
in many projects here, and which contains site and machine parameters.
These modules are related intimately enough to be worth merging.  Doing this
merging, I decided to re-organise and clean the resulting code.

Common usage for the original `defs' already is, a bit everywhere:

        from Local import defs
        ...
        if defs.PARAMETER == VALUE:
            ...

Originally, various PARAMETER were globals within `defs'.  For being
cleaner in `defs', I concentrated its original contents into a class able
to initialise as class members everything that formerly was a global, with
the intent of exposing the class attributes as globals as the last step
in module initialisation.  The goal is to leave all projects' code alone.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list