I'm Brett Slatkin and this is where I write about programming and related topics. You can contact me here or view my projects.

08 January 2013

TIL: Python's @property has a short-hand for setters!
class C(object):
    def __init__(self):
        self._x = None

    @property
    def x(self):
        """I'm the 'x' property."""
        return self._x

    @x.setter
    def x(self, value):
        self._x = value

    @x.deleter
    def x(self):
        del self._x
I've used Python 2.5 for so long I've been unaware of features introduced in 2008. laughcry

My question: How do you use this with Python descriptors generated by a metaclass, like the properties in NDB model classes?
© 2009-2019 Brett Slatkin