Hello
I want to create an object in python that have a few attributes and i want to protect myself from accidently using wrong attribute name. The code is following:
class MyClass( object ) :
m = None # my attribute
__slots__ = ( "m" ) # ensure that object has no _m etc
a = test() # create one
a.m = "?" # here is a PROBLEM
But after running this simple code i got very strange error:
Traceback (most recent call last):
File "test.py", line 8, in <module>
a.m = "?"
AttributeError: 'test' object attribute 'm' is read-only
Any wise programmer who can spare a bit of his time and enlighten me about "read-only" error?