How do I learn operator overriding?
python at sarcastic-horse.com
python at sarcastic-horse.com
Fri Sep 19 14:40:11 EDT 2003
I forgot to mention some things. If I do subtraction between two qDate
objects, I want to get an integer that shows the number of periods (in
this case, quarters) between the two dates:
>>> 2001q1 = qDate(year=2001, quarter=1)
>>> 2001q4 = qDate(year=2001, quarter=4)
>>> 2001q4 - 2001q1
3
But if I subtract an integer from my qDate object, I want to get a new
qDate object returned, like this:
>>> 2001q4 - 2
(new qDate object with year=2001 and quarter=2)
Any ideas how to make this possible?
> 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.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list