[BangPypers] Enclosing lexical context
Anand Balachandran Pillai
abpillai at gmail.com
Thu Apr 15 19:49:08 CEST 2010
On Thu, Apr 15, 2010 at 10:36 PM, Picachu Nioto <picachu.nioto at gmail.com>wrote:
> Could some one explain to me this sentence, I read in an example online
>
> "Python doesn't implement assignment of variables bound in an enclosing
> lexical context"
>
>>> a=[10]
>>> def f(x):
... a[0]=x
... print a
...
>>> f(2)
[2]
>>> print a
[2]
In this case, the outer a is accessed automatically since we are using
indices and there is no local list "a", Python finds the scope from
the global scope and assigns correctly.
> Example,
> a=[b]
>
>
Looking at your code above, perhaps the 2nd explanation
makes it clear.
> --Picachu
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
--
--Anand
More information about the BangPypers
mailing list