Can't subclass datetime.datetime?

Grant Edwards grante at visi.com
Mon Feb 14 15:37:54 EST 2005


On 2005-02-14, Steven Bethard <steven.bethard at gmail.com> wrote:
> Grant Edwards wrote:
>> Is it true that a datetime object can convert itself into a
>> string, but not the other way around?  IOW, there's no simple
>> way to take the output from str(d) and turn it back into d?
>
> I assume this is true because there is not one standard format
> for a date-time string.

There seems to be a de-facto standard format: that which is
returned by the str(d).

>> class MyDatetime(datetime.datetime):
>>     def __init__(self,s):
[...]

> datetime.datetime objects are immutable, so you need to define
> __new__ instead of __init__:

Thanks. I should have known that. I guess I've never subclassed
an immutible type before.

-- 
Grant Edwards                   grante             Yow!  It's hard being
                                  at               an ARTIST!!
                               visi.com            



More information about the Python-list mailing list