简体   繁体   English

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

[英]python comtypes how to pass numpy float32 (singe-precision float) as scalar?

According to comtypes documentation is is possible to pass numpy arrays to comtypes objects, but how to I pass scalar values, eg numpy.float32(1.0) ? 根据comtypes文档,可以将numpy数组传递给comtypes对象,但是如何传递标量值,例如numpy.float32(1.0)

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

I get following error: 我收到以下错误:

---------------------------------------------------------------------------
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

Passing ctypes.c_float rather than np.float32 will work. 传递ctypes.c_float而不是np.float32将起作用。 eg com_obj.Update("string_name", ctypes.c_float(6.6e-6)) . 例如com_obj.Update("string_name", ctypes.c_float(6.6e-6))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM