Properties fun with 2.2

Martin von Loewis loewis at informatik.hu-berlin.de
Wed Dec 26 19:20:02 EST 2001


"Mike C. Fletcher" <mcfletch at rogers.com> writes:

> The "only defined properties" thing can be done with a __slots__ 
> definition in the object, but then there's no __dict__ in which to store 
> the data (there must be some way to say "store in the slot", I just 
> don't see it right now).

Delegating to a different attribute might be appropriate:

class X(object):
    __slots__ = ['_a']
    def set_a(self, val):
        self._a = val
    def get_a(self):
        return self._a
    a = property(get_a, set_a)

Regards,
Martin



More information about the Python-list mailing list