I have a variable and I need to know if it is a datetime object.
So far I have been using the following hack in the function to detect datetime object:
i
While using isinstance will do what you want, it is not very 'pythonic', in the sense that it is better to ask forgiveness than permission.
try:
do_something_small_with_object() #Part of the code that may raise an
#exception if its the wrong object
except StandardError:
handle_case()
else:
do_everything_else()