Simple but fundamental: How to import a jython class?

Fredrik Lundh fredrik at
Thu Mar 23 14:36:07 CET 2006

aziz.hammadi at wrote:

>I wrote a jython class bus I can not use it in another jython script
> :-(
> Example:
> ----------------------
> class X:
> def hello():
> print "Hello"
> ----------------------
> 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, not the class (or any other object) in that module.  to access
the class, use dot notation:

    x = X.X()


More information about the Python-list mailing list