python comtypes如何将numpy float32(singe-precision float)作为标量传递?

时间:2015-09-16 20:17:23

标签: python numpy com cython pywin32

根据comtypes文档可以将numpy数组传递给comtypes对象,但是如何传递标量值,例如numpy.float32(1.0)

https://pythonhosted.org/comtypes/#numpy-interop

我收到以下错误:

---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
<ipython-input-67-9e7e5859c6a5> in <module>()
----> 1 com_obj.Update("string_name",np.float32(6.6e-6))
ArgumentError: argument 2: <type 'exceptions.TypeError'>: Cannot put 6.5999998e-06 in VARIANT

1 个答案:

答案 0 :(得分:2)

传递ctypes.c_float而非np.float32将有效。例如com_obj.Update("string_name", ctypes.c_float(6.6e-6))