小编use*_*686的帖子

从 C# 访问 Ironpython 字典

我在 Ironpython 脚本中定义了字典,我想从我的 C# 代码访问这个字典。有人可以提供示例代码来实现我的要求。

抱歉之前我没有用代码提到我的问题陈述。

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
Run Code Online (Sandbox Code Playgroud)

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);
Run Code Online (Sandbox Code Playgroud)

我的目标是在 python 中的字典列表上操作(添加,从列表中删除)并将其发送回 C#,在那里我可以进一步使用它。我想要的是在 python 或 C# 中创建一个字典列表,并在两个(python 和 C#)的地方使用它。我怎么能这样做。

ironpython c#-4.0

2
推荐指数
1
解决办法
4548
查看次数

标签 统计

c#-4.0 ×1

ironpython ×1