setattr inside a module

kramb64 kramb64 at hotmail.com
Wed Mar 23 05:47:59 EST 2005


On Wed, 23 Mar 2005 11:35:34 +0100, kramb64 <kramb64 at hotmail.com>
wrote:

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


I found this:
	setattr(__import__(__name__), name, value)

But too much underscores.... Nothing better?
Marco.






More information about the Python-list mailing list