setattr inside a module

Denis S. Otkidach ods at
Wed Mar 23 11:58:19 CET 2005

On Wed, 23 Mar 2005 11:35:34 +0100 kramb64 wrote:

K> I'm trying to use setattr inside a module.
K> >From outside a module it's easy:
K> import spam
K> name="hello"
K> value=1
K> setattr(spam, name, value)
K> But if I want to do this inside the module spam itself, what I've to
K> pass to setattr as first argument?

globals()[name] = value


setattr(__import__(__name__), name, value) # note, circular import here

Denis S. Otkidach      [ru]

More information about the Python-list mailing list