我需要使用None初始化實例的所有插槽。我如何獲得派生類的所有插槽? 例(其中不工作): class A(object):
__slots__ = "a"
def __init__(self):
# this does not work for inherited classes
for slot in type(self).__slots__:
我有一棵有成千上萬個節點的大樹,我使用__slots__來減少內存消耗。我只是發現了一個非常奇怪的錯誤並修復了它,但我不明白我看到的行爲。 下面是一個簡單的代碼示例: class NodeBase(object):
__slots__ = ["name"]
def __init__(self, name):
self.name = name
class Node