[sikuli]-导入代码库和Jar

本文介绍如何在Python项目中自动加载库文件,包括如何在不同平台上设置库路径,如何加载Jar文件,以及如何实现库的自动加载和重新加载。详细解释了在各种操作系统环境下设置库路径的方法,并提供了加载Jar文件的功能,还强调了重新加载库的重要性以避免模块重复加载的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

# 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:
  • jar-file – either a filename.jar without any path or the absolute path to filename.jar
Returns:

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)

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值