Simple but fundamental: How to import a jython class?

A

aziz.hammadi

I wrote a jython class bus I can not use it in another jython script
:-(
Example:
---------------------- X.py----------------------
class X:
def hello():
print "Hello"


---------------------- Y.py----------------------
import X
x = X()
x.hello()


I get TypeError: call of non function (module 'X')
Both files are in the same directory.

Tanks!
 
F

Frank Schenk

I wrote a jython class bus I can not use it in another jython script
:-(
Example:
---------------------- X.py----------------------
class X:
def hello():
print "Hello"


---------------------- Y.py----------------------
import X
x = X()
x.hello()


I get TypeError: call of non function (module 'X')
Both files are in the same directory.

try
from X import X
or
x = X.X()


Frank
 
F

Fredrik Lundh

I wrote a jython class bus I can not use it in another jython script
:-(
Example:
---------------------- X.py----------------------
class X:
def hello():
print "Hello"


---------------------- Y.py----------------------
import X
x = X()
x.hello()

I get TypeError: call of non function (module 'X')
Both files are in the same directory.

after you've done "import X", the name X refers to the namespace of the
module X.py, not the class (or any other object) in that module. to access
the class, use dot notation:

x = X.X()

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top