I have 64bit CPython 3.4 installation on windows7. I use the pythonnet package (2.0.0.dev1). I want to instantiate the action delegate, but it gives me an error.
def display(num):
print("num=", num)
import clr
clr.AddReference("System")
import System
paction=System.Action[System.Int32](display)
I get this error:
TypeError Traceback (most recent call last) in () ----> 1 paction=System.Action[System.Int32](display) TypeError: unsubscriptable object
I guess this is the way one shall specify generics.
I have checked the docu and this post, and still do not see the problem. I also palyed around a bit with the Overload method, but did not help either:
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
The problem is that
System.Action
(without arguments and thus not a generic) is shadowingSystem.Action<T>
whileSystem.Func
maps directly toSystem.Func<T>
. I guess this is becauseSystem.Func
will always have a generic parameter and there seems to be an overload implementation in place for generics.The generic's name in Python.NET is
Action`1
(in general:Action`N
withN
being the number of generic arguments). You can get the wrapper object by usinggetattr
on the module: