Python __Slots__ (Making and Using)
问题 I don't really get making a class and using __slots__ can someone make it clearer? For example, I'm trying to make two classes, one is empty the other isn't. I got this so far: class Empty: __slots__ =() def mkEmpty(): return Empty() class NonEmpty(): __slots__ = ('one', 'two') But I don't know how I would make "mkNonEmpty". I'm also unsure about my mkEmpty function. Thanks Edit: This is what I ended up with: class Empty: __slots__ =() def mkEmpty(): return Empty() class NonEmpty(): __slots__