【问题标题】:Python Interpreter Jython - execution of modulesPython解释器Jython - 模块的执行
【发布时间】:2015-07-31 23:07:08
【问题描述】:

这是问题的链接: Python Interpreter in Jython

以下是一个潜在的解决方案:

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

然而它返回了一个错误:

这返回了以下错误:线程“main”中的异常 SyntaxError: ("mismatched input '(' Expecting NEWLINE", ('', 1, 22, 'import os.path.abspath(file)/printTwice.py )\n'))

【问题讨论】:

  • import os.path.abspath(__file__)/printTwice.py) 没有意义。如果printTwice.py 是您尝试导入的模块,则导入语句应为import printTwice
  • 感谢 mzjn 的帮助。

标签: java python jython


【解决方案1】:
interp.exec("import printTwice");
interp.exec("printTwice.print_twice('Adam')");

这应该可行。

【讨论】:

  • 谢谢安德鲁。一旦我弄清楚如何将文件复制到与 Python 控制台相同的工作目录中,我将尝试这个。我会告诉你它是否有效
  • 太棒了,它奏效了。感谢 Andreu 和其他所有做出贡献的人。
猜你喜欢
  • 2017-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多