Action delegate in Python 3.4
I have installed CPython 3.4 64bit and pythonnet-2.1.0.dev1-cp34-none-win_amd64.whl I have tried to use the generic action delegate, but failed. Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
import clr clr.AddReference("System") <System.Reflection.RuntimeAssembly object at 0x0000000002DFAC18> import System def hello(number): ... print(number) ... deleg = System.Action[int](hello) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsubscriptable object
However when I want to instantiate a genrics dictionary then it works.
clr.AddReference("System.Collections") <System.Reflection.RuntimeAssembly object at 0x0000000002397550> import System.Collections.Generic dict = System.Collections.Generic.Dictionary[int,str]() dict[5]="asd" print(dict[5]) asd
Hi, looks like this just hasn't been implemented yet. I don't think it's specific to the 3.4 build. Could you create a github issue with your example if you get a chance? ( https://github.com/pythonnet/pythonnet/) If you want to have a go at implementing it yourself, take a look at the classes DelegateObject (delegateobject.cs) and GenericType (generictype.cs), and the method ClassManager.CreateClass in classmanager.cs. cheers, Tony On Wed, Jul 1, 2015 at 7:35 AM Tamas Ruszkai <ruszkait@gmail.com> wrote:
I have installed CPython 3.4 64bit and pythonnet-2.1.0.dev1-cp34-none-win_amd64.whl
I have tried to use the generic action delegate, but failed.
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
import clr clr.AddReference("System") <System.Reflection.RuntimeAssembly object at 0x0000000002DFAC18> import System def hello(number): ... print(number) ... deleg = System.Action[int](hello) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsubscriptable object
However when I want to instantiate a genrics dictionary then it works.
clr.AddReference("System.Collections") <System.Reflection.RuntimeAssembly object at 0x0000000002397550> import System.Collections.Generic dict = System.Collections.Generic.Dictionary[int,str]() dict[5]="asd" print(dict[5]) asd
Python.NET mailing list - PythonDotNet@python.org https://mail.python.org/mailman/listinfo/pythondotnet
participants (2)
-
Tamas Ruszkai
-
Tony Roberts