datetime gotcha

Frank Millman frank at chagford.com
Fri Dec 13 00:21:48 EST 2019


On 2019-12-11 10:51 PM, Skip Montanaro wrote:
>> Why is a dtm instance also an instance of dt?
> 
> The datetime type is, in fact, a subclass of the date type:
> 
>>>> import datetime
>>>> datetime.date.__bases__
> (<class 'object'>,)
>>>> datetime.datetime.__bases__
> (<class 'datetime.date'>,)
>>>> datetime.time.__bases__
> (<class 'object'>,)
> 
> Skip
> 

Thanks for that.

I found a workaround.

 >>> from datetime import date as dt, datetime as dtm
 >>> type(dtm.now()) is dtm
True
 >>> type(dtm.now()) is dt
False
 >>>

I will run with this.

Frank



More information about the Python-list mailing list