智一面的面试题提供python的测试题
使用地址:http://www.gtalent.cn/exam/interview?token=09b2a6b63e829ef00c112d80fe78d1df

文件名 test.py
使用os.path
方法一:
 
import os 
file_name = os.path.basename(__file__)
print(file_name)
# 输出为 test.py
file_name = file_name.split('.')[0]
print(file_name)
# 输出为 test
 
方法二:
 
stem, suffix = os.path.splitext(filename)
print(stem, suffix) # test   .py
 
使用 pathlib包
 
p = Path(file_name) # test.py
print(p.suffix)  # .py
print(p.stem) # test
 
 
 
————————————————
我们的python技术交流群:941108876
智一面的面试题提供python的测试题
使用地址:http://www.gtalent.cn/exam/interview?token=c7dcd205a4fdab0d6e8ca200b31b3489