最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python基于pyjnius庫(kù)實(shí)現(xiàn)訪問java類

 更新時(shí)間:2020年07月31日 14:31:39   作者:Tracydzf  
這篇文章主要介紹了Python基于pyjnius庫(kù)實(shí)現(xiàn)訪問java類,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

簡(jiǎn)介

Pyjnius是一個(gè)用于訪問Java類的Python庫(kù)。

適用場(chǎng)景:極個(gè)別的加密算法等內(nèi)容,用python不方便實(shí)現(xiàn)或者實(shí)現(xiàn)較耗時(shí),可基于Pyjnius把java類當(dāng)做python庫(kù)使用。

文檔:http://pyjnius.readthedocs.io/en/latest/installation.html

下載地址:https://pypi.python.org/pypi?%3Aaction=search&term=jnius&submit=search

注意jnius的版本管理有點(diǎn)混亂,目前看來選擇jniusx比較好。

git地址:https://github.com/kivy/pyjnius/blob/master/docs/source/index.rst

安裝

先安裝Java JDK 和JRE、Cython

#
pip3 install cython
# pip3 install jniusx
Collecting jniusx
Downloading jniusx - 1.0.5. tar.gz
Requirement already satisfied: six >=
	1.7.0 in /opt/python
3.5 / lib / python3.5 / site - packages(
	from jniusx)
Requirement already satisfied: cython in
	/opt/python
3.5 / lib / python3.5 / site - packages(
	from jniusx)
Installing collected packages: jniusx
Running setup.py install
for jniusx...done
Successfully installed jniusx - 1.0.5

注意:jnius安裝的坑比較多,請(qǐng)參考http://stackoverflow.com/search?q=jnius

如果出現(xiàn)ImportError,一般是java環(huán)境變量或者path沒有配置好。

jnius/jnius.c:4:20: fatal error: Python.h 一般為缺python-dev, yum -y install python-devel

pip 安裝不成功可以嘗試 setup.py方式。

jnius/jnius.c: No such file or directory 需要利用原來保存的clone。

快速入門

hello world 實(shí)例:

#!/usr/bin/env python

#- * -coding: utf - 8 - * -
	#jnius_quick2.py
# Author Rongzhong Xu 2016 - 08 - 02 wechat:
	pythontesting
# https: //bitbucket.org/china-testing/python-chinese-library/src
	""
"
jnius demo
Tested in python2.7
	""
"
from jnius
import autoclass
System = autoclass('java.lang.System')
System.out.println('Hello World')

堆棧實(shí)例:

#!/usr/bin/env python

#- * -coding: utf - 8 - * -
	#jnius_quick1.py
# Author Rongzhong Xu 2016 - 08 - 02 wechat:
	pythontesting
# https: //bitbucket.org/china-testing/python-chinese-library/src
	""
"
jnius demo
Tested in python2.7
	""
"
from jnius
import autoclass
Stack = autoclass('java.util.Stack')
stack = Stack()
stack.push('hello')
stack.push('world')
print(stack.pop())# -- > 'world'
print(stack.pop())# -- > 'hello'

調(diào)用java String的hashCode

#!/usr/bin/env python

#- * -coding: utf - 8 - * -
	#jnius_quick3.py
# Author Rongzhong Xu 2016 - 08 - 02 wechat:
	pythontesting
# https: //bitbucket.org/china-testing/python-chinese-library/src
	""
"
jnius demo: Call java String 's hashCode
Tested in python2.7
	""
"
from jnius
import autoclass
String = autoclass('java.lang.String')
print(String("hello").hashCode())

調(diào)用jar包

#!python

#
vi com / sample / Beach.java
package com.sample;
public class Beach {
	private String name;
	private String city;
	public Beach(String name, String city) {
		this.name = name;
		this.city = city;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
}
#
echo Main - Class: Beach > manifest.txt
# jar cvfm Test.jar manifest.txt com /
	sample /*.class*/

測(cè)試:

#!python

#
ipython
Python 3.5.2(
	default, Nov 7 2016, 18: 53: 51)
Type "copyright", "credits"
or "license"
for more information.
IPython 5.1.0--An enhanced Interactive Python
	.
? - > Introduction and overview of IPython
	's features.
% quickref - > Quick reference.
help - > Python 's own help system.
object ? - > Details about 'object',
	use 'object??'
for extra details.
In[2]: #注意要先把jar加載CLASSPATH環(huán)境變量。
In[3]: from jnius
import autoclass
In[4]: Bla = autoclass(
	'com.sample.Beach')
In[5]: s = Bla("Tom", "Shenzhen")
In[6]: s.getName()
Out[6]: 'Tom'
``
`

封裝某模塊的加密機(jī)制為python包實(shí)例:

* 拷貝: com cn org 到新建的臨時(shí)目錄

* echo Main-Class: AESUtil >manifest.txt

* jar cvfm Test.jar manifest.txt *

測(cè)試代碼:

`
``
python
# - * -coding: utf - 8 - * -
	#注意要先把jar加載CLASSPATH環(huán)境變量。
from jnius
import autoclass
AESUtil = autoclass(
	'com.oppo.sso.util.AESUtil')
email = AESUtil.aesEncrypt(
	"hello@126.com", "我是一個(gè)加密密鑰")
print(email)# !python
# ipython
Python 3.5.2(
	default, Nov 7 2016, 18: 53: 51)
Type "copyright", "credits"
or "license"
for more information.
IPython 5.1.0--An enhanced Interactive Python
	.
? - > Introduction and overview of IPython
	's features.
% quickref - > Quick reference.
help - > Python 's own help system.
object ? - > Details about 'object',
	use 'object??'
for extra details.
In[2]: #注意要先把jar加載CLASSPATH環(huán)境變量。
In[3]: from jnius
import autoclass
In[4]: Bla = autoclass(
	'com.sample.Beach')
In[5]: s = Bla("Tom", "Shenzhen")
In[6]: s.getName()
Out[6]: 'Tom'
``
`

封裝某模塊的加密機(jī)制為python包實(shí)例:

* 拷貝: com cn org 到新建的臨時(shí)目錄

* echo Main-Class: AESUtil >manifest.txt

* jar cvfm Test.jar manifest.txt *

測(cè)試代碼:

`
``
python
# - * -coding: utf - 8 - * -
	#注意要先把jar加載CLASSPATH環(huán)境變量。
from jnius
import autoclass
AESUtil = autoclass(
	'com.oppo.sso.util.AESUtil')
email = AESUtil.aesEncrypt(
	"hello@126.com", "我是一個(gè)加密密鑰")
print(email)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python數(shù)據(jù)處理-導(dǎo)入導(dǎo)出excel數(shù)據(jù)

    Python數(shù)據(jù)處理-導(dǎo)入導(dǎo)出excel數(shù)據(jù)

    這篇文章主要介紹了Python數(shù)據(jù)處理-導(dǎo)入導(dǎo)出excel數(shù)據(jù),Python的一大應(yīng)用就是數(shù)據(jù)分析了,而數(shù)據(jù)分析中,經(jīng)常碰到需要處理Excel數(shù)據(jù)的情況。這里做一個(gè)Python處理Excel數(shù)據(jù)的總結(jié),需要的小伙伴可以參考一下
    2022-01-01
  • 對(duì)Python 檢查文件名是否規(guī)范的實(shí)例詳解

    對(duì)Python 檢查文件名是否規(guī)范的實(shí)例詳解

    今天小編就為大家分享一篇對(duì)Python 檢查文件名是否規(guī)范的實(shí)例詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-06-06
  • 通過celery異步處理一個(gè)查詢?nèi)蝿?wù)的完整代碼

    通過celery異步處理一個(gè)查詢?nèi)蝿?wù)的完整代碼

    今天小編就為大家分享一篇通過celery異步處理一個(gè)查詢?nèi)蝿?wù)的完整代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • python3+PyQt5實(shí)現(xiàn)支持多線程的頁(yè)面索引器應(yīng)用程序

    python3+PyQt5實(shí)現(xiàn)支持多線程的頁(yè)面索引器應(yīng)用程序

    這篇文章主要為大家詳細(xì)介紹了python3+PyQt5實(shí)現(xiàn)支持多線程的頁(yè)面索引器應(yīng)用程序,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • python3.6.8 + pycharm + PyQt5 環(huán)境搭建的圖文教程

    python3.6.8 + pycharm + PyQt5 環(huán)境搭建的圖文教程

    這篇文章主要介紹了python3.6.8 + pycharm + PyQt5 環(huán)境搭建,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-06-06
  • python set內(nèi)置函數(shù)的具體使用

    python set內(nèi)置函數(shù)的具體使用

    這篇文章主要介紹了python set內(nèi)置函數(shù)的具體使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • 使用Python進(jìn)行數(shù)獨(dú)求解詳解(一)

    使用Python進(jìn)行數(shù)獨(dú)求解詳解(一)

    本文主要介紹了如何構(gòu)建一個(gè)Python腳本來解決數(shù)獨(dú)難題,本文的重點(diǎn)在于介紹用于構(gòu)建數(shù)獨(dú)求解器的回溯算法。感興趣的小伙伴可以學(xué)習(xí)一下
    2022-02-02
  • python中pyplot直方圖的繪制方式

    python中pyplot直方圖的繪制方式

    這篇文章主要介紹了python中pyplot直方圖的繪制方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • python?嵌套型partials的使用

    python?嵌套型partials的使用

    這篇文章主要介紹了python?嵌套型partials的使用,partial對(duì)象中包含partial對(duì)象的使用,下文更多詳細(xì)介紹需要的小伙伴可以參考一下
    2022-03-03
  • python flask web服務(wù)實(shí)現(xiàn)更換默認(rèn)端口和IP的方法

    python flask web服務(wù)實(shí)現(xiàn)更換默認(rèn)端口和IP的方法

    今天小編就為大家分享一篇python flask web服務(wù)實(shí)現(xiàn)更換默認(rèn)端口和IP的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-07-07

最新評(píng)論

闵行区| 五大连池市| 盐亭县| 开远市| 成武县| 安岳县| 天镇县| 宝山区| 松江区| 呼玛县| 吴忠市| 桃江县| 寿光市| 兴海县| 万山特区| 基隆市| 米易县| 丽水市| 亚东县| 河曲县| 文昌市| 静海县| 蚌埠市| 商都县| 柳林县| 嵊州市| 砀山县| 永靖县| 杨浦区| 镇远县| 普格县| 博白县| 揭西县| 鄂温| 廉江市| 茌平县| 辽宁省| 安义县| 锡林郭勒盟| 仙居县| 龙州县|