How should I check that a given argument is a datetime.date object?

Posted by rmh on Stack Overflow See other posts from Stack Overflow or by rmh
Published on 2010-05-04T01:31:10Z Indexed on 2010/05/04 1:38 UTC
Read the original article Hit count: 385

Filed under:
|

I'm currently using an assert statement with isinstance. Because datetime is a subclass of date, I also need to check that it isn't an instance of datetime. Surely there's a better way?

from datetime import date, datetime

def some_func(arg):
    assert isinstance(arg, date) and not isinstance(arg, datetime),\
        'arg must be a datetime.date object'
    # ...

© Stack Overflow or respective owner

Related posts about python

Related posts about datetime