add path.fileext which return the file extension

This commit is contained in:
Prodesire 2018-04-12 22:24:03 +08:00
parent ddf87a6f05
commit a5bbfaf3bd
1 changed files with 8 additions and 0 deletions

View File

@ -44,3 +44,11 @@ def normjoin(path, *paths):
def filename(path):
"""Return the filename without extension."""
return os.path.splitext(os.path.basename(path))[0]
def fileext(path):
"""
Return the file extension.
If file has not extension, return empty string.
"""
return os.path.splitext(os.path.basename(path))[1]