[sikuli]-导入代码库和Jar-阿里云开发者社区

开发者社区> 开发与运维> 正文

[sikuli]-导入代码库和Jar

简介:

 

# an example - choose your own naming
# on Windows
myScriptPath = "c:\\someDirectory\\myLibrary"
# on Mac/Linux
myScriptPath = "/someDirectory/myLibrary"

# all systems
if not myScriptPath in sys.path: sys.path.append(myScriptPath)

# supposing there is a myLib.sikuli
import myLib

# supposing myLib.sikuli contains a function "def myFunction():"
myLib.myFunction() # makes the call

# instead of: import module

如果你的代码里没有定义def方法,那么该模块只加载一次,第二次将不在加载。如果你想重新加载,请使用Jython的reload方法。

import module
reload(module)

# instead of: from module import *
import module
reload(module)
from module import *
把你的代码库自动加到项目环境内:
# works on all platforms
import os
# get the directory containing your running .sikuli
myPath = os.path.dirname(getBundlePath())
if not myPath in sys.path: sys.path.append(myPath)

# now you can import every .sikuli in the same directory
import myLib

New in version X1.0-rc3.

Since scripts in same directory are found automatically:

# nothing else needed
# now you can import every .sikuli in the same directory
import myLib

在你的python项目内加载Jar文件

Loading a jar-file containing Java/Python modules

New in version X1.0-rc2.

load(jar-file)

Loads a jar-file and puts the absolute path to it into sys.path, so the Java or Python code in that jar-file can be imported afterwards.

Parameters: Returns:
  • jar-file – either a filename.jar without any path or the absolute path to filename.jar

True if the file was found, otherwise False

Note: if no path is specified, Sikuli first looks into the bundle (the Sikuli folder of the running script) and then into the extensions folder. (more information: Sikuli Extensions)

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章