我有一个python模块,由目录中的import_ical.py
和{
当我使用Jython调用同一个模块时,我得到:
TypeError: 'module' object is not callable
at org.python.core.Py.TypeError(Py.java:263)
at org.python.core.PyObject.__call__(PyObject.java:390)
at org.python.core.PyObject.__call__(PyObject.java:496)
at services.imports.CalendarImporter.importFromUrl(CalendarImporter.java:53)
at services.imports.CalendarImporterTest.testMultipleEventsImport(CalendarImporterTest.java:21)
[...]
CalendarImporter.importFromUrl()执行以下操作:
^{pr2}$当我执行执行这个Jython代码的JUnit测试(CalendarImporterTest
)时,在我的模块目录中生成一个类文件,名为import\ial$py.类。它包含以下行(除其他外):
@Filename("<dir>/import_ical.py")
public class import_ical$py extends PyFunctionTable implements PyRunnable {
[....]
static final PyCode __call__$20;
[....]
public PyObject __call__$20(PyFrame var1, ThreadState var2) {
var1.setline(243);
PyObject var3 = var1.getglobal("import_ical").__call__(var2, var1.getlocal(0), var1.getlocal(1), var1.getlocal(2));
var1.f_lasti = -1;
return var3;
}
}
调试到上面所示的CalendarImporter
Java代码的最后一行,可以得到以下变量状态:
interpreter = {PythonInterpreter}
[...]
globals = {PyStringMap}
table
[...]
1 = {ConcurrentHashMap$MapEntry} "import_ical" -> "<module 'import_ical' from '<dir>/import_ical$py.class'>"
[...]
[...]
[...]
importIcalPy = {PyModule}
[...]
__dict__ = {PyStringMap}
table
[...]
19 = {ConcurrentHashMap$MapEntry} "import_ical" -> "<function import_ical at 0xc>"
[...]
32 = {ConcurrentHashMap$MapEntry} "__call__" -> "<function __call__ at 0x13>"
[...]
[...]
[...]
作为一个python新手,我无法检测到任何会引起我对模块生成的类文件的怀疑的东西,甚至上面显示的变量状态似乎都告诉我在python模块importIcalPy
中有一个正确的函数__call__
。在
注意:我已经将函数__call__
添加到python模块中,以便通过Jython“调用”该模块并捕获此错误—显然没有成功。在
那么有谁能告诉我:为什么我会得到“不可调用”的错误?我能做些什么来阻止它呢?非常感谢您的帮助-谢谢!在
[注释:我在Stackoverflow和使用一个大型搜索引擎的情况下都强烈地搜索了一个解决方案,但是所有的搜索结果都会导致另一个问题,即python模块无法调用另一个python模块。]
最后,多亏了user2357112的提示,我找到了一个修复程序。替换的内容CalendarImporter.importFromUrl()上面显示了以下代码:
希望,它会帮助别人。在
相关问题 更多 >
编程相关推荐