现在的位置: 首页 > 综合 > 正文

Python_如何使用Python访问Java类(2)

2013年10月12日 ⁄ 综合 ⁄ 共 506字 ⁄ 字号 评论关闭

    下载下来代码后就需要进行安装了:

1. 首先切换到目录pyjnius-master下,然后输入命令: sudo python setup.py install

2.安装完成后输入命令: sudo make

3. 然后输入命令: sudo make tests

以上三步都成功后就可以编写代码运行了,例子如下:

PyJNIus

Python module to access Java class as Python class, using JNI.

(Work in progress.)

Quick overview

>>> from jnius import autoclass
>>> autoclass('java.lang.System').out.println('Hello world')
Hello world

>>> Stack = autoclass('java.util.Stack')
>>> stack = Stack()
>>> stack.push('hello')
>>> stack.push('world')
>>> print stack.pop()
world
>>> print stack.pop()
hello

请参考:https://github.com/kivy/pyjnius

抱歉!评论已关闭.