Alter python descriptor
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
No comments:
Post a Comment