How do I learn operator overriding?

python at sarcastic-horse.com python at sarcastic-horse.com
Fri Sep 19 14:25:23 EDT 2003


Hi-


I need to make a class for quartlerly dates.  I need to be able to compare
two quarterly dates and get the number of quarters between them.  For
example:

>>> 2001q1 = qDate(year=2001, quarter=1)
>>> 2001q4 = qDate(year=2001, quarter=4)
>>> 2001q4 - 2001q1
3

The only problem is that I have no idea how to override operators in
python.  Can anyone give me a few trivial examples of how it is done?

And, on a completely unrelated note, I am getting a truly amazing amount
of spam today.  Anyone else?


Thanks for the help.





More information about the Python-list mailing list