Using Python descriptors with slots
问题 I want to be able use python descriptors in a class which has the slots optimization: class C(object): __slots__ = ['a'] a = MyDescriptor('a') def __init__(self, val): self.a = val The problem I have is how to implement the descriptor class in order to be able to store values in the class instance which invokes the descriptor object. The usual solution would look like the one below but will not work since "dict" is no longer defined when "slots" is invoked in the C class: class MyDescriptor