【发布时间】:2021-06-14 19:55:53
【问题描述】:
我在Python3中使用c# dll,我使用的模块是 DaveSkender/Stock.Indicators 它是用 C# 编写的,符合公共语言规范 (CLS)。 所以我把它编译为dll 并在 Python3 中导入,如下所示:
import clr
clr.AddReference(r'dll/Skender.Stock.Indicators')
到目前为止,它可以正常工作并且可以确保模块成功导入。 但问题是传递参数。 C# DLL 中有这样的方法:
public static IEnumerable<SmaResult> GetSma<TQuote>(
IEnumerable<TQuote> history,
int lookbackPeriod)
where TQuote : IQuote
{
// WHATEVER
}
所以我在 Python 中这样传递参数:
from System.Collections.Generic import List
// Definitely, Qoute is inherited from IQoute
history_list = List[Qoute]()
Indicator.GetSma(history_list, int(1))
但是一直显示TypeError:
TypeError: No method matches given arguments for GetSma: (<class 'System.Collections.Generic.0, Culture=neutral, PublicKeyToken=null]]'>, <class 'int'>)
我不知道 Python 中哪种类型与 C# 兼容。 我应该在这个方法中传递什么? 我的意思是我应该在 Python 中为 IEnumerable 传递什么?
【问题讨论】:
-
也许是其他参数? python中的int是怎么定义的?
-
顺便说一下,您正在显示 GetSmaExtended 方法,但您正在使用(或尝试使用)GetSma 方法。
-
@Ralf 哦,感谢您对此感兴趣。我修复了它,但没有什么不同。 :)
标签: python c# clr python.net