Import os path1 = os.path.dirname (__file__) print (path1) # Gets the absolute path of the currently running script path2 = os.path.dirname (Os.path.dirname (__file__)) # print (path2) #获取当前运行脚本的绝对路径 (remove the last path) path3 = os.path.dirname ( Os.path.dirname (Os.path.dirname (__file__))) print (PATH3) #获取当前运行脚本的绝对路径 (remove the last 2 paths) path4 = os.path.dirname (Os.path.dirname (Os.path.dirname (Os.path.dirname (__file__))) print (PATH4) #获取当前运行脚本的绝对路径 (remove the last 3 paths) path5 = os.path.dirname ( Os.path.dirname (Os.path.dirname (Os.path.dirname (Os.path.dirname (__file__)))) print (PATH5) # Gets the absolute path of the currently running script (minus the last 4 paths) path6 = os.__file__ #获取os所在的目录 print ( PATH6) project = os.path.abspath (__file__) Projectpath = os.path.dirname (project) print (project) print (ProjectPath)
Python Get file path