Don Taylor wrote: > I am puzzled about the following piece of code which attempts to create > a class that can be used as record or struct with a limited set of > allowed attributes that can be set into an instance of the class. > > I don't understand why I cannot set an attribute 'age' into record1.
First advice (which also appears in the documentation): stay away from using __slots__. It may seem like a good idea at first, but my experience has taught me that it will cause problems, sooner or later (apparently sooner for you). I might be a little confused about a couple of things (I'm sure many will correct me if I'm not), but as I understand it the __slots__ attribute is a class-attribute, which means it cannot be modified by an instance of the class (think of a "static" class member, if you know C++). IMHO, __slots__ is unpythonic. Many others have stated so on the list. That's why it's great that you're free to ignore that variable. I suggest that you do so (as I have chosen to do). I'm sure that there are situations where you *MUST* have this kind of capability, but I haven't bumped into them yet. -- Steve Juranich Tucson, AZ USA -- http://mail.python.org/mailman/listinfo/python-list