class
Foo
:
class Foo():
def __init__(self):
del self.foo
def foo(self):
pass
当实例化raise
s时AttributeError: Foo instance has no attribute 'foo'
。源自( ) s 。Foo
_ 使用也无济于事。object
class Foo(object)
raise
AttributeError: 'Foo' object attribute 'foo' is read-only
delattr(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
如果满足某些条件,我基本上想从给定的实例中完全删除/或使某些属性无法访问。
有什么建议么?