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

posted @ 2023-02-22 16:31  vx_guanchaoguo0  阅读(38)  评论(0编辑  收藏  举报