class Foo:
class Foo():
def __init__(self):
del self.foo
def foo(self):
pass
当实例化raises时AttributeError: Foo instance has no attribute 'foo'。源自( ) s 。Foo_ 使用也无济于事。objectclass Foo(object)raiseAttributeError: 'Foo' object attribute 'foo' is read-onlydelattr(self, "foo")
执行以下操作也不会从Foo的实例中删除属性:
class Foo():
def __init__(self):
self.foo = None
del self.foo
def foo(self):
pass
>>> Foo().foo
<bound method Foo.foo of <__main__.Foo instance at 0x00000000042EA248>>
客观的:
class如果满足某些条件,我基本上想从给定的实例中完全删除/或使某些属性无法访问。
有什么建议么?