problem with 'global'

oyster lepto.python at gmail.com
Mon Jan 21 04:21:40 CET 2008


why the following 2 prg give different results? a.py is ok, but b.py
is 'undefiend a'
I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC
v.1310 32 bit (Intel)] on win32
#a.py
def run():
        if 1==2:                # note, it always False
        global a
        a=1

run()
a

#b.py
def run():
        a=1

run()
a



More information about the Python-list mailing list