explain this

Steve Holden sholden at holdenweb.com
Tue Jul 3 15:43:33 EDT 2001


Plus, of course, the second call to locals() inside function() gets a *new
copy* of the local namespace, which still has "argument" in it despite your
attempt to delete it. You're just lucky the addition worked. Don't mess with
locals()!

--
http://www.holdenweb.com/


"gods1child" <alankarmisra at hotmail.com> wrote in message
news:25b2e0d9.0107031136.5dc0dad2 at posting.google.com...
> In the code below, why can i add elements to locals but not delete them?
>
> >>> def function(argument):
> ... print locals()
> ... modify(locals())
> ... print locals()
> ...
> >>> def modify(locals):
> ... del locals['argument']
> ... locals['new_argument'] = 'new_value'
> ...
> >>> function(10)
> {'argument': 10}
> {'argument': 10, 'new_argument': 'new_value'}





More information about the Python-list mailing list