Question on statically nested scopes

Manus Hand manus at bullfrog-tech.com
Thu Aug 29 22:56:51 CEST 2002


Sorry for the typo:  you need it to be vars(self).update(locals())

Manus

Sean 'Shaleh' Perry wrote:

> On Thursday 29 August 2002 11:45, 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.).
> >
>
> >>> class Foo:
> ...     def doit(self, **params):
> ...         vars().update(locals())
> ...
> >>> f = Foo()
> >>> f.doit(a=1, b=2, c=3)
> >>> f.a
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: Foo instance has no attribute 'a'
>
> This is python 2.2.1 from my Debian system.




More information about the Python-list mailing list