global variable not seen (bug?)

Peter Hansen peter at engcorp.com
Wed Jan 8 21:49:17 EST 2003


Dennis Lee Bieber wrote:
> 
> There is a second factor to account for. There is no access (or wasn't
> -- did 2.2 or 2.3 change that?) to intermediate levels. 

It would appear... see below, or http://www.amk.ca/python/2.1/ for
the definitive guide.

> PseudoPython
> a
> def p1
>         b
>         def p2
>                 c
>                 def p3
>                         d
>                         # I can only see d and a, and need global to change a

Actual Python, since 2.1:

Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Alternative ReadLine 1.5 -- Copyright 2001, Chris Gonnerman
>>> a = 5
>>> def p1():
...   b = 6
...   print a, b
...   def p2():
...     c = 7
...     print a, b, c
...     def p3():
...        d = 8
...        print a, b, c, d
...     p3()
...   p2()
...
>>> p1()
5 6
5 6 7
5 6 7 8
>>>

-Peter




More information about the Python-list mailing list