Question on statically nested scopes

Manus Hand manus at bullfrog-tech.com
Thu Aug 29 21:04:02 CEST 2002


Okay, so my code snippet wasn't 100% accurate.  Change "locals()" to
"params"

Manus (who copied the top line from function X -- which used a ** parameter
--
and the second line from function Y -- which named all the incoming
parameters on
the def line -- while typing the post; sorry about that.  Just goes to show
you that I
use stuff like this all the time, though, doesn't it?)

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.).
>
> Can someone PLEASE assure me that this still works in 2.2, given PEP
> 227, which seems to state that the vars() and locals() dictionaries are
> going to henceforth be made read-only (which, if you'll pardon my
> French, would really really suck, so I hope I'm misreading it)?
>
> Thanks,
> Manus Hand




More information about the Python-list mailing list