Using Python 2.7. Tried to import a global variable counter
from testlib.py
, in uselib.py
, but return result is 0
in below program in uselib.py
, why 2
is not returned? Thanks.
testlib.py,
counter = 0
class Foo:
def __init__(self):
pass
def Count(self):
global counter
counter += 1
uselib.py,
from testlib import Foo
from testlib import counter
f = Foo()
f.Count()
g = Foo()
g.Count()
print counter # output is 0 other than 2