[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)

 

 

你可能感兴趣的:(sikuli)