I've this python descriptor:
# Date Descriptor
class DateAttribute():
    def __init__(self, value=None):
        self.value = value
    def __get__(self, instance, value):
        return self.value
    def __set__(self, instance, value):
        if type(value) is not datetime.date: 
            raise TypeError('A date value is expected')
        self.value = value
and a class D that use this descriptor:
class D:
    thisdate = DateAttribute()
I use this class as:
x = D()
x.thisdate = datetime.date(2012, 9, 12)
I wish to extend the descriptor to give me formatted results in some ways. Es.
x.thisdate.format1
>>> '2012 9 12'
x.thisdate.format2
>>> '2012___9___12'
x.thisdate.format3
>>> '2012####9####12'
.....
I could do this ?
Thanks
format1,format2etc... attribute (or properties). I.e.x.thisdatewill not return a stringx.thisdate = datetime.date(…). As you have it, you've made a class DateAttribute that does absolutely nothing. A poor reason for using a descriptor is "because that's how I had to do it in Java/C++ and I haven't understood why Python doesn't have private instance variables."