我有字典在Ironpython腳本中定義,我想從我的C# 代碼訪問此字典。有人可以提供示例代碼來實現我的要求。來自C的訪問Ironpython字典#
對不起,我沒有提到我的代碼問題陳述。
import clr
clr.AddReference("System.Core")
import System
clr.ImportExtensions(System.Linq)
from System.Collections.Generic import Dictionary,List
def check(self):
dict1 = Dictionary[str,str]
dict1["a"] = "aa"
dict2 = Dictionary[str,str]
dict2["b"] = "bb"
self[0] = dict1
# self.Add(dict1)
return self
C#
var runtime = Python.CreateRuntime();
dynamic test = runtime.UseFile("Test.py");
var myDictList = new List<Dictionary<string, string>>();
var myDL = new List<Dictionary<string, string>>();
myDL = test.check(myDictList);
我的目標是在python的字典順序操作(添加,從列表中刪除),併發送回C#在那裏我可以進一步使用它。 我想要的是要麼在Python或C#中創建一個字典的列表,並在(Python和C#)這兩個地方使用它。 我該怎麼做。
爲您的努力提供代碼會讓其他人更好地幫助您 – Ramunas 2013-04-29 13:08:40