how to test for pywintypes.datetime type with isinstance?


I am pulling a range from excel including dates. If I check for types this is what I get:

pywintypes.datetime(2009, 10, 26, 0, 0, tzinfo=TimeZoneInfo('GMT Standard Time', True))

I am doing a check on it using isinstance(q, pywintypes.datetime) but it doesnt work.

isinstance(q, pywintypes.datetime)
Traceback (most recent call last):
  File "", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-47-916010697275>", line 1, in <module>
    isinstance(q, pywintypes.datetime)
AttributeError: module 'pywintypes' has no attribute 'datetime'

any idea how to test via isinstance to check if its a pywintypes object?


Asked By: Steven G



Please try the following code:

import datetime

isinstance(q, datetime.datetime)
Answered By: TimothyW

looks like this works:

from pywintypes import TimeType

if type(date) is TimeType:
Answered By: Steven G

The code snippet below worked for me. I couldn’t get this "from pywintypes import TimeType" to work because I’m also using win32api which seems to interfere with TimeType.

import pywintypes
print(type(q) is pywintypes.TimeType)
Answered By: JSotelo
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.