【发布时间】:2023-03-12 16:20:01
【问题描述】:
我有一个问题,我有这样的代码
this._engine = Python.CreateEngine();
ScriptSource source = this._engine.CreateScriptSourceFromString(script.SourceCode);
ScriptScope scope = this._engine.CreateScope();
ObjectOperations operations = this._engine.Operations;
source.Execute(scope);
我正在尝试执行教程中的 IronPython 代码:
from System.Collections import BitArray
ba = BitArray(5)
ba.Set(0, True) # call the Set method
print ba[0]
所以它执行正确,但我不明白我是否有print ba[0] 为什么它不将此值输出到控制台?顺便问一下,您能否推荐一些关于使用 IronPython 编写应用程序脚本的好文章?
另外一个问题是,如果我有一些 Python 类并且我不知道这个类的名称,因为客户端可以手动定义它,是否可以创建这个类的实例?例如
class SomeClass(object):
def some(self, a, b):
return <something>
现在我正在尝试使用此代码
dynamic SomeClass = scope.GetVariable("SomeClass");
dynamic something = SomeClass();
something.some(x,y);
我应该遍历ScriptScope.GetItems() 集合并搜索PythonType 对象吗?
【问题讨论】:
标签: c# dynamic ironpython