Python: how can I check whether an object is of type datetime.date?

后端 未结 7 1181
既然无缘
既然无缘 2020-12-24 10:16

I have tried a few obvious options but none of them works:

In [150]: x
Out[150]: datetime.date(2012, 9, 1)

In [151]: type(x)
Out[151]: datetime.date

In [15         


        
7条回答
  •  时光取名叫无心
    2020-12-24 10:54

    right way is

    import datetime
    isinstance(x, datetime.date)
    

    When I try this on my machine it works fine. You need to look into why datetime.date is not a class. Are you perhaps masking it with something else? or not referencing it correctly for your import?

提交回复
热议问题