手记

python获取文件所在目录和文件名,以及检索当前文件名的方法

python获取文件所在目录和文件名,以及检索当前文件名的方法

print(__file__)print(sys.argv[0])print(os.path.dirname(__file__))print(os.path.split(__file__)[-1])print(os.path.split(__file__)[-1].split('.')[0])

对应的返回结果:

D:/office3/python/python_py/compare/test.pyD:/office3/python/python_py/compare/test.pyD:/office3/python/python_py/comparetest.py
test


0人推荐
随时随地看视频
慕课网APP