Having problem with IronPython to instantiate a class in IronPython Console
-
05-07-2019 - |
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?
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 :)