Question on statically nested scopes

holger krekel pyth at devel.trillke.net
Fri Aug 30 15:22:47 EDT 2002


Bayzuldin Timur wrote:
> 
> > 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
> 
> Python 2.2 (#1, Aug 26 2002, 04:40:34)
> [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>>Class Foo:
> ...	def Some(self, **params):
> ...		vars(self).update(locals().values()[1])

why not simply 
            vars(self).update(params)
?




More information about the Python-list mailing list