我有以下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运行此代码时,我收到以下错误。
Traceback (most recent call last): File ipycallcs, line unknown, in Initialize NameError: name 'Arith' is not defined
可能出现什么问题?
arith = Arith()应该是arith = MyMath.Arith()
答案 0 :(得分:6)
您应该执行以下操作:
from MyMath import Arith
或者:
from MyMath import *
否则,您必须将Arith
类称为MyMath.Arith。