accessing module global vars by name

Martin Drautzburg martin.drautzburg at
Mon Dec 20 08:18:16 CET 2004

Withing a module I can assign a value to a global var by assigning to
it in the outermost scope. Fine.

But how can I do this if the attribute name itself is kept in a
variable. Once the module is loaded I can access the module's
namespace no problem, but inside the module the dictionary is not yet
present right ?

IOW how can I write something like


for varName in ("foo", "bar"):
        magic.varName = 1

so I can later refer to them as 

        import xxx
        x =
        y =

More information about the Python-list mailing list