Apologies, somewhat confused Python newbie question. Let's say I have a module called animals.py
.......
globvar = 1
class dog:
def bark(self):
print globvar
class cat:
def miaow(self):
print globvar
What is the difference between this and
class dog:
def __init__(self):
global globvar
def bark(self):
print globvar
class cat:
def miaow(self):
print globvar
Assuming I always instantiate a dog first?
I guess my question is, is there any difference? In the second example, does initiating the dog
create a module level globvar
just like in the first example, that will behave the same and have the same scope?