Local and enclosing are lexical myPython doesn't have lexicals. All variables are rather some equivalent of package variables, where each function counts as a package that can't access variables of other function. So a variable can be used as long as it as been defined sometime before in the function, regardless of scope:
I had some difficulty understanding the meaning and use of with statements, until I realized it was just a mechanism to simulate lexical scope (with the possibility to do some clean up on a variable at the end of a defined scope). You might find some example when looking for variable declaration in python, but actually the (new) feature is just type enforcing, there is no equivalent to my in python.>>> def scope(): ... for x in range(1,10): ... if x > 3: ... print(a) ... else: ... a=x ... >>> scope() 3 3 3 3 3 3 >>> print(a) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'a' is not defined
That's the thing I dislike the most about python, just above the lack of explicit block-ending tokens (curly brackets :P).
In reply to Re^2: Nesting Functions
by Eily
in thread Nesting Functions
by betmatt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |