AW: The rules of reference
Gerson Kurz
Gerson.Kurz at t-online.de
Thu Oct 31 14:21:25 EST 2002
Jeff Epler wrote
> The code in "a.py" is executed once when it's named on the commandline
> (inside a module called '__main__') and then again when 'import a' is
> executed (inside a module called 'a')
Well, yes. But take again a look at the code of a.py:
num = 42
def print_num():
global num
print "a.print_num() called, num is %d" % num
if __name__ == "__main__":
import b
print "Step 1: num should be 42"
print_num()
num = 60
print "Step 2: num should be 60"
print_num()
print "Step 3: num should *still* be 60, but is probably not:"
b.do_stuff()
As you can see, the assignment "num = 60" is called *after* "import b". I
know that "import b" does a recursive "import a", but *that is already done*
at the time I do the "num=60" bit. So this is what I don't get.
More information about the Python-list
mailing list