相关疑难解决方法(0)

Python NET 调用具有返回值和输出参数的 C# 方法

我有以下静态 C# 方法

public static bool TryParse (string s, out double result)
Run Code Online (Sandbox Code Playgroud)

我想使用 Python NET 包从 Python 调用它。

import clr
from System import Double
r0 = Double.IsNaN(12.3) # works

r1, d1 = Double.TryParse("12.3") # fails! TypeError: No method matches given arguments. This works in IronPython.

d2 = 0.0
r2, d2 = Double.TryParse("12.3", d2) # fails! TypeError: No method matches given arguments
Run Code Online (Sandbox Code Playgroud)

任何的想法?

更新

我找到了以下答案,请参阅/sf/answers/1372024461/

使用 PythonNet 的 CPython 基本上做同样的事情。处理参数的简单方法是不传递它们并接受它们作为额外的返回值,对于 ref 参数,将输入值作为参数传递并接受输出值作为额外的返回值。

这会声称r1, d1 = Double.TryParse("12.3")应该有效,但事实并非如此。

c# python out python-3.x python.net

4
推荐指数
1
解决办法
3007
查看次数

标签 统计

c# ×1

out ×1

python ×1

python-3.x ×1

python.net ×1