python分离文件路径和文件名,文件名和后缀名
程序员文章站
2022-06-12 14:06:59
...
python分离文件路径和文件名,文件名和后缀名
In [1]: import os
In [2]: file_path=r'E:\data\test1001.csv'
In [3]: path,file=os.path.split(file_path)
In [4]: path
Out[4]: 'E:\\data'
In [5]: file
Out[5]: 'test1001.csv'
In [6]: file_name,suffix=file.split('.')
In [7]: file_name
Out[7]: 'test1001'
In [8]: suffix
Out[8]: 'csv'