3

I have the following C# code to compile it into MyMath.dll assembly.

namespace MyMath {
    public class Arith {
        public Arith() {}
        public int Add(int x, int y) {
            return x + y;
        }
    }
}

And I have the following IronPython code to use this object.

import clr
clr.AddReferenceToFile("MyMath.dll")

import MyMath
arith = Arith()
print arith.Add(10,20)

When I run this code with IronPython, I get the following error.

Traceback (most recent call last):
  File ipycallcs, line unknown, in Initialize
NameError: name 'Arith' is not defined

What might be wrong?

ADDED

arith = Arith() should have been arith = MyMath.Arith()

3
  • 1
    Shouldn't it be arith = MyMath.Arith()? Commented Oct 10, 2010 at 20:40
  • @Mark : Yes, that was the problem, thanks. Commented Oct 10, 2010 at 20:43
  • for fixing common errors in IronPython try this Beginning IronPython Commented Jun 12, 2013 at 18:58

1 Answer 1

6

You should be doing the following:

from MyMath import Arith

Or:

from MyMath import *

Otherwise, you'll have to refer to the Arith class as MyMath.Arith.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.