Python3 获取当前文件名


#__author: mac
#date: 2018/12/16

import os
import sys

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

结果为:

/Users/mac/PycharmProjects/sina/test.py
/Users/mac/PycharmProjects/sina/test.py
/Users/mac/PycharmProjects/sina
('/Users/mac/PycharmProjects/sina', 'test.py')
test.py
test

 

posted @ 2018-12-16 16:30  小鳄鱼DL  阅读(11331)  评论(0编辑  收藏  举报