【发布时间】:2012-06-15 05:01:28
【问题描述】:
在我的 C# 代码中,我有一个类,它存储了一些我希望在列表中传递给我的 python 代码的数据。但是,当我尝试在我的 python 代码中访问该类的属性时,我得到MissingMemberException。这里有一些示例代码来说明我的意思:
C#:
class Event
{
public int EventId { get; set; }
public string EventName { get; set; }
}
//other processing here...
//this just fills the list with event objects
List<Event> eventList = GetEvents();
//this sets a variable in the ScriptScope
PythonEngine.SetVariable( "events", eventList);
PythonEngine.Execute("eventParser.py");
eventParser.py:
for e in events:
print e.EventId, " / ", e.EventName
MissingMemberException 表示“事件不包含名为 EventId 的成员”
我已经测试过将其他类型传递给 python,包括基本类型列表,如 List< int > 和 List< string >,它们工作正常。
那么如何在我的 python 脚本中访问这些类属性 EventId 和 EventName?
【问题讨论】:
标签: c# ironpython