str2 = "Global"
class InClass:
str2 = "Class"
def Set(self, msg):
self.str2 = msg
def Print(self):
print(str2)
g = InClass()
g.Set("Instance")
g.Print()
If I run this code, I get "Global" as result. But I cannot understand why.
By calling Set() method of instance g, variable str2 is now in the namespace of instance g. Then, following LGB scoping rule, the namespace of instance g is the first namespace where str2 can be found! So, the result should be "Instance".
Is this wrong?