faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 2 people (100%) answered Yes
Recently 1 of 1 people (100%) answered Yes

Entry

Importing modules in JPython

Jul 5th, 2000 09:59
Nathan Wallace, Hans Nowak, Snippet 12, Jim Hugunin


"""
Packages: jpython
"""

"""
> I am new to JPython.
>
> Can you explain me how to import my own classes into JPython, please ?
>
> Example:
>
> All what follows was compiled and put into a location accessible by
> CLASSPATH.
> However JPython can't find it:
> ---------------------------------------
> >>> from mytest import Foo
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> ImportError: no module named mytest

JPython needs to be explicitly told about any Java packages other than the
standard ones.  Try the following:
"""

# this code won't work if you don't use JPython -- PSST

import sys
sys.add_package('mytest')
from mytest import Foo

"""
There are other options to do the same thing described in the JPython
documentation under docs/usejava.html in the section on importing.
"""