updating local()

Steve Holden steve at holdenweb.com
Wed Oct 5 12:40:49 EDT 2005


Flavio wrote:
> Hi,
> 
>  I heard time and again that you are not _supposed_ to update the
> locals dictionary.
> 
> Can anyone tell me why, if the following code works, I should not do
> this?
> 
> #
> # Extending Local namespace
> #
> 
> def fun(a=1,b=2,**args):
> 
> 	print 'locals:',locals()
> 	locals().update(args)
> 	print locals()
> 
> e = {'s':3,'e':4}
> fun(k=10,v=32,**e)
> 
Because it depends on the current implementation and isn't guaranteeed 
to work in the future.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list