如何检查PyWin时间类型

2024-06-25 05:46:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图检查PyWin在带有Excel的COM接口中返回的数据是否属于“time”类型。在

以下是不起作用的代码:

from win32com.client import Dispatch
from pywintypes import Time
cellToTest = Dispatch('Excel.Application').Sheets('SomeSheet').Range('SomeCell').Value
if type( cellToTest ) == Time:
    print 'It\'s an excel time type'

因为这:type(Time)

返回这个:<type 'builtin_function_or_method'>

但是这个:type(cellToTest)

返回这个:<type 'time'>


Tags: 数据代码fromimportcomclient类型time
1条回答
网友
1楼 · 发布于 2024-06-25 05:46:53

Time不是一个类型,而是一个返回新时间对象(http://docs.activestate.com/activepython/2.4/pywin32/pywintypes__Time_meth.html)的函数。我不知道win32软件包中的实际类型位于何处,但您可以创建任意时间对象并询问其类型:

type(cellToTest) == type(Time(1))

相关问题 更多 >