[Python-Dev] fuzzy logic?

Tim Peters tim.one@home.com
Thu, 14 Dec 2000 12:33:41 -0500


Note that the behavior of both functions is undefined ("Names listed in a
global statement must not be used in the same code block textually preceding
that global statement", from the Lang Ref, and "if" does not introduce a new
code block in Python's terminology).

But you'll get the same outcome via these trivial variants, which sidestep
that problem:

def spam():
    if (0):
        global a
        print "global a"
    a = 2

def egg():
    if 0:
        global b
        print "global b"
    b = 2

*Now* you can complain <wink>.


> -----Original Message-----
> From: python-dev-admin@python.org [mailto:python-dev-admin@python.org]On
> Behalf Of Fredrik Lundh
> Sent: Thursday, December 14, 2000 8:19 AM
> To: python-dev@python.org
> Subject: [Python-Dev] fuzzy logic?
>
>
> here's a simple (but somewhat strange) test program:
>
> def spam():
>     a = 1
>     if (0):
>         global a
>         print "global a"
>     a = 2
>
> def egg():
>     b = 1
>     if 0:
>         global b
>         print "global b"
>     b = 2
>
> egg()
> spam()
>
> print a
> print b
>
> if I run this under 1.5.2, I get:
>
>     2
>     Traceback (innermost last):
>         File "<stdin>", line 19, in ?
>     NameError: b
>
> </F>
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev@python.org
> http://www.python.org/mailman/listinfo/python-dev