Question on statically nested scopes
holger krekel
pyth at devel.trillke.net
Thu Aug 29 15:30:59 EDT 2002
Manus Hand wrote:
> In my code, I use a very handy trick:
>
> class Whatever:
> def someFunction(self, **params):
> vars().update(locals())
>
> This means that whatever named variables I pass into "someFunction"
> become attributes of the object (accessible with self.varName, etc.).
What do you think PEP227 (statically nested scopes) has to do
with this whole issue?
And you probably meant 'vars(self).update(params)'.
But anyway, you could do
def someFunction(self, **params):
for key,value in params:
setattr(self, key, value)
and
def someFunction(self, **params):
self.__dict__.update(locals())
and don't have to worry much :-)
regards,
holger
More information about the Python-list
mailing list