I want to create an object in python that has a few attributes and I want to protect myself from accidentally using the wrong attribute name. The code is as follows:
<
__slots__ works with instance variables, whereas what you have there is a class variable. This is how you should be doing it:
__slots__
class MyClass( object ) : __slots__ = ( "m", ) def __init__(self): self.m = None a = MyClass() a.m = "?" # No error