Adding to a module's __dict__?
jeanmichel at sequans.com
Tue Mar 2 11:29:33 CET 2010
Roy Smith wrote:
> >From inside a module, I want to add a key-value pair to the module's
> __dict__. I know I can just do:
> FOO = 'bar'
> at the module top-level, but I've got 'FOO' as a string and what I
> really need to do is
> __dict__['Foo'] = 'bar'
> When I do that, I get "NameError: name '__dict__' is not defined". Is
> it possible to do what I'm trying to do?
setattr(sys.modules[__name__], varName, 42)
in a shell:
More information about the Python-list