The rules of reference

Gerson Kurz gerson.kurz at t-online.de
Thu Oct 31 14:01:37 EST 2002


On Thu, 31 Oct 2002 18:52:12 GMT, gerson.kurz at t-online.de (Gerson
Kurz) wrote:

uupps. Corrected modules:

------- (a2.py) -------------

# change from "b" to "b2"

if __name__ == "__main__":
    import b2, c
    print "Step 1: num should be 42"
    c.print_num()
    c.num = 60
    print "Step 2: num should be 60"
    c.print_num()
    print "Step 2: num should *still* be 60, but is probably not:"
    b2.do_stuff()
   

-------- (b2.py) ------

import c

def do_stuff():
    print "b.do_stuff() called"
    c.print_num()

-------- (c.py) -----
# posting had wrong line

print "this is c, don't mess with me."

num = 42

def print_num():
    global num
    print "c.print_num() called, num is %d" % num

---------------------
gives the correct output:

this is c, don't mess with me.
Step 1: num should be 42
c.print_num() called, num is 42
Step 2: num should be 60
c.print_num() called, num is 60
Step 2: num should *still* be 60, but is probably not:
b.do_stuff() called
c.print_num() called, num is 60



ok, but I still find that kinda lame... but what the heck, it works.







More information about the Python-list mailing list