Python获取文件名不带扩展名的方法:
import os <a href="https://www.gaodaima.com/tag/file" title="查看更多关于file的文章" target="_blank">file</a>_<a href="https://www.gaodaima.com/tag/name" title="查看更多关于name的文章" target="_blank">name</a> = os.path.basename(__file__) print(file_name) # 输出为 test.py file_name = file_name.split('.')[0] print(file_name) # 输出为 test
www#gaodaima.com来源gaodai#ma#com搞@@代~&码网搞代码
搞代码网,大量的免费python教程,欢迎在线学习!
来源:搞代码网:原文地址:https://www.gaodaima.com