获得脚本路径可以直接用 __file__,也可以稳妥选择os.path.abspath(__file__)
如
absDir=__file__
但有时候需要获得脚本所在文件夹的路径,在上面的基础上,只需要再加一步
absDir=__file__
thisDir=os.path.dirname(absDir)
或者一步到位,简化为thisDir=os.path.dirname(__file__)
获得脚本路径可以直接用 __file__,也可以稳妥选择os.path.abspath(__file__)
如
absDir=__file__
但有时候需要获得脚本所在文件夹的路径,在上面的基础上,只需要再加一步
absDir=__file__
thisDir=os.path.dirname(absDir)
或者一步到位,简化为thisDir=os.path.dirname(__file__)