从IronPython调用C#对象
我有以下C#代码将其编译为MyMath.dll程序集。
namespace MyMath { public class Arith { public Arith() {} public int Add(int x, int y) { return x + y; } } }
我有以下IronPython代码来使用此对象。
import clr clr.AddReferenceToFile("MyMath.dll") import MyMath arith = Arith() print arith.Add(10,20)
当我使用IronPython运行此代码时,我收到以下错误。
回溯(最近的呼叫最后): 在初始化中将文件ipycallcs,行未知 NameError:未定义名称“Arith”
可能有什么问题?
添加
arith = Arith()应该是arith = MyMath.Arith()
你应该做以下事情:
from MyMath import Arith
要么:
from MyMath import *
否则,您必须将Arith
类称为MyMath.Arith。