1

I'm trying to learn IronPython. I created an extremely simple class like this one:

class Test:
  def testMethod(self):
    print "test"

Next I'm trying to use it in IronPython Console:

>>> import Test
>>> t = Test()

After the second line I get following error:

TypeError: Scope is not callable

What I'm doing wrong?

2 Answers 2

4

you need to from filename import Test where filename is a basename of file class Test is saved in.

e.g.: class Test is saved in test.py

then:

from test import Test
t = Test()

will run as expected.

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

1 Comment

that's did it. Thanks a lot.
2

import Test loads the module named Test, defined in a file called Test.py(c|d). This module in turn contains your class named Test. You're trying to instantiate the module called Test. To instantiate the class Test in module Test, you need to use:

t = Test.Test()

This concept can be quite tricky, especially if you have a background in other languages. Took me a while to figure out too :)

1 Comment

Thanks for the explanation. You're absolutely correct. Too bad I had to accept only one answer. SlientGhost was first. +1 for you.

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.