osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

datetime gotcha


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