【发布时间】:2014-08-15 23:16:05
【问题描述】:
我尝试在我的类上使用弱引用,我使用插槽来节省一些内存,但我无法创建派生类。
class A(object):
__slots__ = ['__weakref__']
class B(A):
__slots__ = A.__slots__ + ['foo']
#TypeError: Error when calling the metaclass bases
# __weakref__ slot disallowed: either we already got one, or __itemsize__ != 0
诀窍在哪里?我没有找到任何解决方案。我正在使用 python 2.7.3。
【问题讨论】:
标签: python inheritance weak-references