我试图检查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'>
Time不是一个类型,而是一个返回新时间对象(http://docs.activestate.com/activepython/2.4/pywin32/pywintypes__Time_meth.html)的函数。我不知道win32软件包中的实际类型位于何处,但您可以创建任意时间对象并询问其类型:
相关问题 更多 >
编程相关推荐