Overriding class variables and destroying overriden references in python classes

Input:
class foo(object):
    ref = None
    def setup(self):
        self.ref = 1234
    def clear(self):
        del self.ref

obj = foo()
print obj.ref
obj.setup()
print obj.ref
obj.clear()
print obj.ref

O
utput:
None
1234
None

Comments

Popular posts from this blog

Multiple repeat error when the regex has multiple wildcards in python re module

Avoid using global/class-level mutable datatypes like list/dicts

Weakref proxy is for instance only ...