Question on statically nested scopes

Sean 'Shaleh' Perry shalehperry at attbi.com
Thu Aug 29 15:09:24 EDT 2002


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