python3 提取扩展名
Python provides built in module to extract the file extension from the file name.
Python提供了内置模块,用于从文件名中提取文件扩展名 。
Before python3
在python3之前
The os.path module provides a function called splitext method, which splits the pathname path into file name and file extension.
os.path模块提供了一个名为splitext method的功能,该功能将路径名路径分为文件名和文件扩展名。
Example:
例:
>>> import os
>>> file_name = 'includehelp.txt'
>>> print(os.path.splitext(file_name))
('includehelp', '.txt')
>>>
After python3
在python3之后
In the path from pathlib, us