views:

99

answers:

2

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

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.

SilentGhost
that's did it. Thanks a lot.
Vadim
+2  A: 

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

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