【发布时间】:2019-07-08 14:09:30
【问题描述】:
我有以下静态 C# 方法
public static bool TryParse (string s, out double result)
我想使用 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
有什么想法吗?
更新
我找到了以下答案,见https://stackoverflow.com/a/19600349/7556646。
使用 PythonNet 的 CPython 基本上做同样的事情。最简单的方法 do out参数是不传递它们并接受它们作为额外的回报 值,以及 ref 参数将输入值作为参数传递 并接受输出值作为额外的返回值。
这会声称r1, d1 = Double.TryParse("12.3") 应该可以工作,但它没有。
【问题讨论】:
标签: c# python python-3.x out python.net