【发布时间】:2019-04-26 05:58:15
【问题描述】:
有没有办法使用 Python 从预定义的 C++ 函数中获取变量的值?我有 C++ 函数,它以 variant 类型作为参数。但是我们不能在python中定义variant类型变量,对吧?我尝试过使用Boost.Python、pybind11。但是由于我无法编辑预定义的功能,所以无法实现它们。
编辑:
我有一个名为 bcap 的 C++ 函数,它接受 2 个参数并返回 2 个值。
# C++ code
# Takes these arguments
int32 func_id
variant[] vntArgs
---
# Returns these values
int32 HRESULT
variant vntRet
而variant[] vntArgs有2种变量。
int16 vt
string value
我正在尝试使用这些参数调用此函数。
#python code
func_id = 3
vt = 8
value_1 = 'value: b-CAP'
value_2 = 'CaoProv.DENSO.VRC'
value_3 = 'localhost'
value_4 = ''
vntArgs = [vt, value_1, vt, value_2, vt, value_3, vt, value_4]
response = bcap(func_id, vntArgs)
#store the response in some variables
result1 = response.HRESULT
result2 = response.vntRet
问题是当我运行这个程序时,出现了这个错误。
AttributeError: 'int' object has no attribute 'vt'
我该怎么办?
提前致谢。
【问题讨论】:
-
具体来说,您的
variant类型是什么? -
正如我在上面添加的,它是
int16 and string。