oddities in the datetime module

Serge Orlov Serge.Orlov at gmail.com
Fri Jan 14 17:45:49 EST 2005


Max M wrote:
> Serge Orlov wrote:
>> Max M wrote:
>
>> Yes, you did. datetime.timetuple is those who want *time module*
>> format, you should use datetime.data, datetime.time, datetime.year
>> and so on... As they say, if the only tool you have is timetuple, everything
>> looks like tuple <wink> Try this:
>>
>>>>> dt = datetime(2005, 1, 1, 12, 0, 0)
>>>>> dt.date()
>>
>> datetime.date(2005, 1, 1)
>
> This doesn't solve it. I don't think you understand my issue.

I understand, but I don't think it's something that should be solved. Especially
date(*dt.timetuple()[:3])


> class my_datetime(datetime):
>
>     def __add__(self, other):
>         result = datetime.__add__(self, other)
>         return my_datetime(result.timetuple()[:6])
>

What about:

def __add__(self, other):
    result = datetime.__add__(self, other)
    return my_datetime.fromdatetime(result)

  Serge. 





More information about the Python-list mailing list