Here is a variation on the method described below. It assumes that you have the python code that defines your methods stored in a Sting. This allows you to retrieve the function definitions  from a database, resource, hardcoded string, etc.


       static final  String code = "def helloWorld():\n   print 'Hello World\n'";   // example using a hardcoded string

....

       interp_ = new InteractiveConsole();
       code = code.trim();
        StringTokenizer st = new StringTokenizer
            (code, System.getProperty("line.separator"));
        while (st.hasMoreTokens())
        {
            String lineOfCode = st.nextToken();
            interp_.push(lineOfCode);
        }

....


-Paul




- I would also like to expose some python functions into the global
namespace of any executed python script. These functions are actually
implemented in Java and provide some app-specific functionality to the
python environment.

I'm not one of the 'experts', but this is how I do it and it seems to work=
fine; just 'execfile' the file with the functions:

InputStream functionFileStream =3D FileIO.FindFileOrStream(=
functionListName, dataPath, "functions", debugLevel);
python.execfile( functionFileStream, functionListName); // pass the name=
for parsing errors

This way the names are scoped into the top level.

(My 'FindFileOrStream' finds the function file in a file or jar in the=
'dataPath'. I have a list of functions files in an XML configuration=
file.)

- Jim



-- Paul Giotta Software Architect Technoparkstrasse 1, CH-8005 Zurich. Email: paul.giotta@Softwired-inc.com Home Page WWW: http://www.softwired-inc.com *Next stop UBIQUITY!* Office: +41 1 4452370 | Fax: +41 1 4452372 | Mobile: +41 76 389 1180 *** Go Mobile: Out NOW: iBus//Mobile 2.1 *** ***iBus//MessageServer 4.5 with XA extensions***