Re: accessing module global vars by name

2004-12-20 Thread Peter Hansen
Martin Drautzburg wrote: 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 t

Re: accessing module global vars by name

2004-12-19 Thread Steven Bethard
Martin Drautzburg wrote: IOW how can I write something like # xxx.py for varName in ("foo", "bar"): magic.varName = 1 I think you want to use the dict returned by globals(). Modifying this dict can add/remove names from the global scope.[1] >>> foo Traceback (most recent call last): Fi

accessing module global vars by name

2004-12-19 Thread Martin Drautzburg
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