implementing descriptors

Mark Lawrence breamoreboy at
Fri Aug 14 01:19:29 CEST 2009

dippim wrote:
> I am new to Python and I have a question about descriptors.  If I have
> a class as written below, is there a way to use descriptors to be
> certain that the datetime in start is always before the one in end?
> class foo(object):
>    def __init__(self,a = None,b = None)
>       self.start = a
>       self.end = b
> from datetime import datetime
> c = datetime(2009,8,13,6,15,0)
> d = datetime(2009,8,14,12,0,0)
> afoo = foo(c,d)
> For instance, if the following code were run, I would like to instance
> of foo to switch the start and end times.
> afoo.start = datetime(2010,8,13,6,15,0)
> I was thinking of using the __set__ descriptor to catch the assignment
> and reverse the values if necessary, but I can't figure out how to
> determine which values is being set.
> Thanks for the help!
> David
Take a look at the example given here.

Kindest regards.

Mark Lawrence.

More information about the Python-list mailing list