【发布时间】:2018-12-05 23:00:20
【问题描述】:
我试图从 DLL 中运行名为“functionName”的函数,同时从 python 项目中调用它。我已经控制了许多 DLL 的函数,但是在运行“functionName”时,我相信我对 pythonnet 的 C# 数组列表的列表实现存在问题。
我试图调用的 DLL 中的行
public int functionName(ArrayList data)
目前我尝试通过以下方式创建一个python ArrayList:
from System import Int32
from System import Array
data1 = [Int32(x) for x in data1] # data1 is a list
data1 = Array[Int32](data1) # ArrayList Expecting 8x Arrays to be added
import clr
clr.AddReference('System.Collections')
from System.Collections.Generic import List # Avoids Deprecation
Py_Array = System.Collections.Generic.List[Array[Int32]]()
Py_Array.Add(data1)
...
Py_Array.Add(data1) # 8 times total
DLL.functionName(Py_Array)
结果一直是:
TypeError: No method matches given arguments
我尝试了很多不同的方法来解决这个问题,我相信问题可能属于 System.Collections.Generic.List 与 C# 的预期类型 ArrayList 不匹配。
任何帮助将不胜感激。
编辑#1
我发现还有一个:
System.Collections.ArrayList()
但这并没有解决方法匹配给出参数的问题
【问题讨论】:
-
您是否尝试通过
Overloads或反射强制方法签名? pythonnet.github.io
标签: c# python .net overloading python.net