Message9161
Some user of ours is trying to run an existing script which uses __file__ and finding that the value is undefined.
I distilled it down to a test case which I have verified on 2.7b3:
public static void main(String[] args) throws Exception {
ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("py");
engine.put(ScriptEngine.FILENAME, "/tmp/some_script.py");
System.out.println(engine.eval("__file__"));
}
Instead of printing the filename of the script, you get an exception:
javax.script.ScriptException: NameError: name '__file__' is not defined in /tmp/some_script.py at line number 1
at org.python.jsr223.PyScriptEngine.scriptException(PyScriptEngine.java:202)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:42)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
As an ironic twist, the error message itself the filename, so clearly *someone* knows the filename.
For the sake of comparison, the test program for JRuby's equivalent constant prints out the filename:
public void testJRuby() throws Exception
{
ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("rb");
engine.put(ScriptEngine.FILENAME, "/tmp/some_script.rb");
System.out.println(engine.eval("__FILE__"));
} |
|
Date |
User |
Action |
Args |
2014-10-20 00:29:14 | jythonuser1 | set | recipients:
+ jythonuser1 |
2014-10-20 00:29:14 | jythonuser1 | set | messageid: <1413764954.88.0.756044219139.issue2223@psf.upfronthosting.co.za> |
2014-10-20 00:29:14 | jythonuser1 | link | issue2223 messages |
2014-10-20 00:29:13 | jythonuser1 | create | |
|