python 提取文件的名字 和路径
# coding=utf-8
import sys
import os
s = 'C:/Users/Desktop/lesson/python/calss1.py'
m_dir = os.path.dirname(s) # 输出为 'C:/Users/Desktop/lesson/python'
m_file = os.path.basename(s) # 输出为 class1.py
if __name__ == '__main__':
print("m_dir = ", os.path.dirname(s))
print("m_file = ", os.path.basename(s))
stem, suffix = os.path.splitext(m_file)
print("suffix = ", suffix[1:]) # class1 ------- .py
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/17144864.html