[英]System.Collections.Generic lists in Python 'TypeError: type(s) expeected' error
I am trying to run the following piece of code:我正在尝试运行以下代码:
import clr
import sys
#import System.Collections
clr.AddReference("System.Collections")
from System.Collections.Generic import List
from System import String
class MyClass(object):
def __init__(self, e=""):
self.title = e
li = List[MyClass]()
list(li)
However, I am getting the error 'TypeError: type(s) expected' and cannot understand how to solve it.但是,我收到错误“TypeError: type(s) expected”并且无法理解如何解决它。
This is related to System.Collections.Generic lists in Python这与 System.Collections.Python 中的通用列表有关
Thanks!谢谢!
In Python.NET you can't use .NET lists to store Python objects in a strongly-typed way unless you do one of the following:在 Python.NET 中,您不能使用 .NET 列表以强类型方式存储 Python 对象,除非您执行以下操作之一:
class MyClass(System.Object):
# without __namespace__ - regular Python type
__namespace__ = "MyNamespace"
use List<System.Object>
or List<Python.Runtime.PyObject>
使用List<System.Object>
或List<Python.Runtime.PyObject>
have a List<X>
with a Python to .NET codec for the .NET type X
对于List<X>
type X
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.