shaiel cohen
shaiel cohen

Reputation: 41

Python NET create generic dictionary with object as a type for the value

How do I create a dictionary of string, object in Python using Python NET?

C#

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

Python

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

Upvotes: 3

Views: 2726

Answers (1)

Wollmich
Wollmich

Reputation: 1646

You can create it like that:

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

Upvotes: 2

Related Questions