|
From: Robert W. B. <rb...@di...> - 2001-05-30 19:59:20
|
On Wed, 30 May 2001, Romain Guy wrote:
> Does Jython provides an equivalent of Python 2.1 __main__ ?
yes...
[sh:~/.] jython
Jython 2.1a1 on java1.3.1 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> print __name__
__main__
>>>
The top-level script environment isn't automatic when embedding...
// file: test.java
import java.util.Properties;
import org.python.core.*;
import org.python.util.*;
public class test {
private static PythonInterpreter interp;
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("python.home", "/home/rbill/jython-2.1a1");
PythonInterpreter.initialize(System.getProperties(), props, new String[0]);
interp = new PythonInterpreter();
// explicitly add __main__
PyModule mod = imp.addModule("__main__");
interp.setLocals(mod.__dict__);
interp.execfile(args[0]);
}
}
cheers,
robert
|