- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 windows7 上安装了 64 位 CPython 3.4。我使用 pythonnet 包 (2.0.0.dev1)。我想实例化 Action 委托(delegate),但它给我一个错误。
def display(num):
print("num=", num)
import clr
clr.AddReference("System")
import System
paction=System.Action[System.Int32](display)
我收到这个错误:
TypeError Traceback (most recent call last) in () ----> 1 paction=System.Action[System.Int32](display) TypeError: unsubscriptable object
我想这就是指定泛型的方式。
我检查了文档和this发帖,还是没看出问题。我也尝试了一下 Overload 方法,但也没有帮助:
paction=System.Action.Overloads[System.Int32](display)
TypeError Traceback (most recent call last) in () ----> 1 paction=System.Action.Overloads[System.Int32](display) TypeError: No match found for constructor signature
最佳答案
问题是 System.Action
(没有参数,因此不是通用的)正在隐藏 System.Action<T>
同时 System.Func
直接映射到 System.Func<T>
.我想这是因为 System.Func
将总是有一个泛型参数,并且似乎有一个针对泛型的重载实现。
泛型在 Python.NET 中的名称是 Action`1
(通常:Action`N
,N
是通用参数的数量)。您可以使用 getattr
获取包装器对象在模块上:
Action = getattr(System, "Action`1")
action = Action[Int32](display)
关于c# - python3 pythonnet 泛型代表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30659933/
我是一名优秀的程序员,十分优秀!