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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4