且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何知道 Python 中正在运行的脚本的路径?

更新时间:2023-10-20 15:27:34

Per the great Dive进入Python:

Per the great Dive Into Python:

import sys, os

print 'sys.argv[0] =', sys.argv[0]             1
pathname = os.path.dirname(sys.argv[0])        2
print 'path =', pathname
print 'full path =', os.path.abspath(pathname)