Class Variable Access and Assignment

Mike Meyer mwm at mired.org
Fri Nov 4 18:08:46 EST 2005


Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> Mike Meyer <mwm at mired.org> writes:
>> I've already argued that the kludges suggested to "solve" this problem
>> create worse problems than this.
> The most obvious solution is to permit (or even require) the
> programmer to list the instance variables as part of the class
> definition.  Anything not in the list is not an instance variable,
> i.e. they don't get created dynamically.  That's what most other
> languages I can think of do.  Some Python users incorrectly think this
> is what __slots__ does, and try to use __slots__ that way.  That they
> try to do that suggests that the approach makes some sense.

That breaks the ability to add attributes dynamically, which is
usefull. If you need an extra piece of data with some existing class,
it's much easier to just add an attribute to hold it than to create a
subclass for the sole purpose of adding that attribute.

      <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list