Python Interpreter Jython - execution of modules

2019-06-03 08:32发布

问题:

Here's the link to the problem: Python Interpreter in Jython

The following was a potential solution:

    interp.exec("import os.path.abspath(__file__)/printTwice.py)");
    interp.exec("printTwice.print_twice('Adam')");

However it returned an error:

This returned the following error: Exception in thread "main" SyntaxError: ("mismatched input '(' expecting NEWLINE", ('', 1, 22, 'import os.path.abspath(file)/printTwice.py)\n'))

回答1:

interp.exec("import printTwice");
interp.exec("printTwice.print_twice('Adam')");

This should work.