None assigment

Tim Peters tim.one at home.com
Fri Feb 9 02:22:10 EST 2001


[Aahz and Rainer Deyke, volley over a stupid-ass program too long
 without changing topics <wink>]

> b=2
> def foo():
>     b=4
>     print b
>     del b
>     global b
>     print b
> foo()

Just noting that the program's behavior is undefined, so "works" vs "doesn't
work" is a bogus argument (Ref Man, "global" stmt):

    Names listed in a global statement must not be used in the
    same code block textually preceding that global statement.

    ...

    (The current implementation does not enforce the latter two
    restrictions, but programs should not abuse this freedom, as
    future implementations may enforce them or silently change
    the meaning of the program.)

Which is a lot like saying we left bear traps set all over the room, and you
shouldn't abuse your freedom by stepping into one lest you lose a foot or
two <0.9 wink>.

So why doesn't the compiler check for that and gripe?  Don't know.  A good
guess is because Guido figured he had more important things to do at the
time.

and-if-we-knew-what-they-were-i-bet-we'd-agree-ly y'rs  - tim





More information about the Python-list mailing list