how to test for pywintypes.datetime type with isinstance?
Question:
I am pulling a range from excel including dates. If I check for types this is what I get:
type(q)
Out[45]:
pywintypes.datetime
q
Out[46]:
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 "C:Anaconda2envspy36libsite-packagesIPythoncoreinteractiveshell.py", 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?
thanks
Answers:
Please try the following code:
import datetime
isinstance(q, datetime.datetime)
looks like this works:
from pywintypes import TimeType
if type(date) is TimeType:
print('date!')
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)
I am pulling a range from excel including dates. If I check for types this is what I get:
type(q)
Out[45]:
pywintypes.datetime
q
Out[46]:
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 "C:Anaconda2envspy36libsite-packagesIPythoncoreinteractiveshell.py", 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?
thanks
Please try the following code:
import datetime
isinstance(q, datetime.datetime)
looks like this works:
from pywintypes import TimeType
if type(date) is TimeType:
print('date!')
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)