在 Jython(和 Gephi)中查找

发布于 2024-11-07 00:50:24 字数 846 浏览 1 评论 0原文

我尝试在 Jython 中使用 Gephi Toolkit,但遇到问题。代码如下:

import sys
sys.path.append('gephi-toolkit.jar')
from org.openide.util import Lookup
import org.gephi.project.api.ProjectController as ProjectController

pc = Lookup.getDefault().lookup(ProjectController)
workspace = pc.newProject()

print "done."

它永远不会到达最后一行。相反,会出现以下错误:

Traceback (most recent call last):
  File "standalone.py", line 9, in <module>
    workspace = pc.newProject()
AttributeError: 'NoneType' object has no attribute 'newProject'

显然,“Lookup.getDefault().lookup(ProjectController)”返回 None 。谁能告诉我为什么?我发现以下解决方法有效(绕过查找):

...
import org.gephi.project.impl.ProjectControllerImpl as ProjectControllerImpl
pc = ProjectControllerImpl()
workspace = pc.newProject()

我想了解有关此问题的更多信息。谢谢。

I'm trying to use Gephi Toolkit in Jython, but having problems with it. The code is below:

import sys
sys.path.append('gephi-toolkit.jar')
from org.openide.util import Lookup
import org.gephi.project.api.ProjectController as ProjectController

pc = Lookup.getDefault().lookup(ProjectController)
workspace = pc.newProject()

print "done."

It never reaches the last line. Instead gives the following error:

Traceback (most recent call last):
  File "standalone.py", line 9, in <module>
    workspace = pc.newProject()
AttributeError: 'NoneType' object has no attribute 'newProject'

Apparently, "Lookup.getDefault().lookup(ProjectController)" is returning None. Can anyone tell me why? I found that the following workaround works (which bypasses Lookup):

...
import org.gephi.project.impl.ProjectControllerImpl as ProjectControllerImpl
pc = ProjectControllerImpl()
workspace = pc.newProject()

I'd like to know more about this issue. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风蛊 2024-11-14 00:50:24

我认为这是因为查找需要引用 java 类,而不是 jython 包装器

尝试这个,看看它是否适合你,至少对我来说它返回 org.gephi.project.impl.ProjectControllerImpl 的实例

导入系统

从 org.openide.util 导入查找

导入java.lang.Class

导入 org.gephi.project.api.ProjectController 作为 ProjectController

pc = Lookup.getDefault().lookup(java.lang.Class.forName("org.gephi.project.api.ProjectController"))

打印(电脑)


调用使用(更改为安装 gephi 的位置)

设置 CLASSPATH=%CLASSPATH%;C:\java\gephi-toolkit-0.7.2014-all\gephi-toolkit.jar

jython.bat gephi_test.jy

您应该看到类似

C 的 内容:\jython2.5.2>jython.bat gephi_test.jy

org.gephi.project.impl.ProjectControllerImpl@8ddb93

i think it's because the lookup needs a reference to the java class, not the jython wrapper

try this and see if it works for you,for me at least it returns an instance of org.gephi.project.impl.ProjectControllerImpl

import sys

from org.openide.util import Lookup

import java.lang.Class

import org.gephi.project.api.ProjectController as ProjectController

pc = Lookup.getDefault().lookup(java.lang.Class.forName("org.gephi.project.api.ProjectController"))

print(pc)


invoke using (change to wherever your gephi is installed)

set CLASSPATH=%CLASSPATH%;C:\java\gephi-toolkit-0.7.2014-all\gephi-toolkit.jar

jython.bat gephi_test.jy

you should see something like

C:\jython2.5.2>jython.bat gephi_test.jy

org.gephi.project.impl.ProjectControllerImpl@8ddb93

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文