我有PVPython的主脚本,它运行大约3-5个下标。除了薪酬之外,我还必须指定下标路径才能这样运行:
'/home/username/Documents/MainFolder/Subscripts/subscript1.py'是否有一种方法可以像主脚本一样自动获得此路径,例如,在下面的主文件夹中:
'/home/username/Documents/MainFolder/Masters/master1.py'当我从PVPython 就像这里运行一个相对路径引用时,我会得到一个错误,所以在PVPython中可能还有另一种方法?
谢谢你的建议
编辑
问题是
import sys
print(sys.path[0])我被印出来了
/usr/lib/python38.zip发布于 2020-08-18 08:28:29
在指向(https://note.nkmk.me/en/python-script-file-path/)的链接中,有一个节Get the absolute path of the running file。
使用
os.path.abspath(__file__)获得主脚本的绝对路径。然后,您可以从相对的订阅重新创建订阅的绝对路径(请参阅os doc:https://docs.python.org/3/library/os.path.html)
https://stackoverflow.com/questions/63231258
复制相似问题