Python NET使用对象作为值的类型创建通用字典

时间:2018-10-15 07:33:38

标签: python dictionary generics python.net

如何使用Python NET在Python中创建字符串,对象的字典?

C#

d = new Dictionary<string,object>() // works

Python

Dictionary [string, object] # TypeError : type(s) expected

1 个答案:

答案 0 :(得分:0)

您可以这样创建它:

import clr
from System.Collections.Generic import Dictionary
from System import String
from System import Object
d = Dictionary[String, Object]()
d['Entry 1'] = 'test'
d['Entry 2'] = 12.3
d.Count # returns 2