>>> import os
>>> homedir = os.getcwd()
>>> print homedir
D:\python\test
>>>
>>> import sys
>>> print sys.argv[0]
D:\python\test\temp.py
>>> print os.path.abspath(sys.argv[0])
D:\python\test\temp.py
>>>
转载于:https://www.cnblogs.com/mfryf/p/3806135.html