python comtypes 如何将 numpy float32(单精度浮点数)作为标量传递?
python comtypes how to pass numpy float32 (singe-precision float) as scalar?
根据 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
传递 ctypes.c_float
而不是 np.float32
会起作用。例如com_obj.Update("string_name", ctypes.c_float(6.6e-6))
.
根据 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
传递 ctypes.c_float
而不是 np.float32
会起作用。例如com_obj.Update("string_name", ctypes.c_float(6.6e-6))
.