python - 如何使用 CPython 让泛型在 Python.NET 中工作

标签 python .net clr ironpython python.net

如何使用 CPython 让泛型在 Python.NET 中工作。使用 Python.NET Using Generics 中的下标语法时出现错误

TypeError: unsubscriptable object

使用 Python 2.7.11 + pythonnet==2.1.0.dev1

>python.exe
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> from System import EventHandler
>>> from System import EventArgs
>>> EventHandler[EventArgs]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsubscriptable object

我也尝试过 pythonnet==2.0.0 并使用 ReleaseWin x86 构建 github ca15fe8 形式并得到了同样的错误。

使用 IronPython-2.7.5:

>ipy.exe
IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.0 (32-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> from System import EventHandler
>>> from System import EventArgs
>>> EventHandler[EventArgs]
<type 'EventHandler[EventArgs]'>

最佳答案

您可以显式获取泛型类对象:

EventHandler = getattr(System, 'EventHandler`1')

数字表示通用参数的数量。

关于python - 如何使用 CPython 让泛型在 Python.NET 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35494331/

相关文章:

python - 使用 SQLite 在 SQLAlchemy 中返回不同的行

python - django 中的分页 - 原始查询字符串丢失

python - Pip 安装不适用于 Scikit-Learn

c# - 如何单独替换组的每个捕获?

python - 更改字体大小而不影响 Tkinter 按钮大小

c# - 与 Func<TResult> 相同的操作?

c# - System.Net.Mail.MailMessage,将图像添加到邮件消息

c++ - Windows 窗体声音文件不存在以及如何检索嵌入的声音 (C++)

.net - 是否有任何 ECMAScript 的 .NET CLR/DLR 实现?

com - 'COM context' MDA 消息中引用的 'ContextSwitchDeadlock' 是什么?