Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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 :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top