私の Python 2.7.3 プロジェクトには、custom_dateというプロパティを持つ というクラスがありfixed_dateます。
from datetime import date
class custom_date():
def __init__(self, fixed_date):
self.fixed_date = fixed_date
def __lt__(self, other):
return self.fixed_date < other
#__gt__, __ge__, __le__, __eq__, __ne__ all implemented the same way
custom_date.fixed_date私の考えは、ビルトインと直接比較できるようにすることdateです。
問題
custom_dateオブジェクトとオブジェクトを比較すると、date問題ありません。dateただし、オブジェクトをと比較するとcustom_date、TypeError
>>> from datetime import date
>>> x = custom_date(date(2013,2,1))
>>> y = date(2013,2,2)
>>> x > y
False
>>> y > x
TypeError: can't compare datetime.date to instance
これを回避する方法はありますか?