Python .NET创建泛型字典,对象作为值的类型

问题描述 投票:2回答:1

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

C#

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

蟒蛇

Dictionary [string, object] # TypeError : type(s) expected
python dictionary generics python.net
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.