M
Manavan
Hello everyone,
Since the real world objects often needs to be deleted even if they
have some reference from some other object, I am going to use this
approach to better model this situation, by cleaning up the attributes
and assigning self.__class__ to a different class.
Any comment on this approach.
class Deleted(object):
pass
class RealWorldObj(object):
def __init__(self, *args):
self.attrs = args
def getAttrs(self,):
return self.attrs
def delete(self,):
del self.attrs
self.__class__ = Deleted
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Deleted' object has no attribute 'attrs'
Since the real world objects often needs to be deleted even if they
have some reference from some other object, I am going to use this
approach to better model this situation, by cleaning up the attributes
and assigning self.__class__ to a different class.
Any comment on this approach.
class Deleted(object):
pass
class RealWorldObj(object):
def __init__(self, *args):
self.attrs = args
def getAttrs(self,):
return self.attrs
def delete(self,):
del self.attrs
self.__class__ = Deleted
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Deleted' object has no attribute 'attrs'