Is there a function to extract the extension from a filename?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
That will give you the file name up to the first ".", which would be the most common.
You can find some great stuff in pathlib module.
Although it is an old topic, but i wonder why there is none mentioning a very simple api of python called rpartition in this case:
to get extension of a given file absolute path, you can simply type:
example:
will give you: 'csv'
Just
join
allpathlib suffixes
.One option may be splitting from dot:
No error when file doesn't have an extension:
But you must be careful: