Sikuli 获取文件路径的一部分 - 分割字符串
我想从 Sikuli - Jython 中当前文件的文件路径中获取一个数字,
我有一个我想要实现的 python 示例。
在示例中路径是: C:\PycharmProjects\TestingPython\TestScripts\TestScript_3.sikuli\TestScript.py
import os
PointerLeft = "Script_"
PointerRight = ".sikuli"
FilePath = os.path.dirname(os.path.abspath(__file__))
NumberIWant = FilePath[FilePath.index(PointerLeft) + len(PointerLeft):FilePath.index(PointerRight)]
print(NumberIWant)
所以我想要得到的是数字 3。在 python 中,上面的示例有效,但我无法在 Sikulix 中使用 __file__
ref 。字符串的分割也不起作用,所以即使我得到了路径的字符串,我仍然必须得到数字。
非常感谢任何帮助和/或想法
I want to get a number from the filepath of the current file in Sikuli - Jython
I have a python example of what i'm trying to achive.
In the example the path is:
C:\PycharmProjects\TestingPython\TestScripts\TestScript_3.sikuli\TestScript.py
import os
PointerLeft = "Script_"
PointerRight = ".sikuli"
FilePath = os.path.dirname(os.path.abspath(__file__))
NumberIWant = FilePath[FilePath.index(PointerLeft) + len(PointerLeft):FilePath.index(PointerRight)]
print(NumberIWant)
So what i want to get is the number 3. In python the example above works, but I cant use the __file__
ref in Sikulix. Nor does the split of the string work, so even if I get the string of the path, I still have to get the number.
Any help and/or ideas is greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重要的:
.sikuli
文件夹中的.py
文件必须具有相同的名称因此,在您的情况下:
...\TestScript_3.sikuli\TestScript_3.py
看起来您正在尝试在
PyCharm
上下文中运行您的东西。如果您不在 SikuliX IDE 中运行脚本,则必须将from sikuli import *
添加到主脚本中。要获取脚本的文件路径,请使用 getBundlePath()。
然后 os.path(getBundlePath()).basename() 将生成字符串“TestScript_3.sikuli”。
SikuliX 的 RaiMan
Important:
the
.py
file in a.sikuli
folder must have the same namehence in your case:
...\TestScript_3.sikuli\TestScript_3.py
It looks like you are trying to run your stuff in the
PyCharm
context. If you do not run the script in the SikuliX IDE, you have to addfrom sikuli import *
even to the main script.To get the file path of the script use
getBundlePath()
.Then
os.path(getBundlePath()).basename()
will result to the string"TestScript_3.sikuli"
.RaiMan from SikuliX