How to use Pathlib module In Python
The pathlib.Path().suffix method of the Pathlib module can be used to extract the extension of the file path. This method is preferred for an object-oriented approach.
Python3
import pathlib # function to return the file extension file_extension = pathlib.Path( 'my_file.txt' ).suffix print ( "File Extension: " , file_extension) |
Output:
File Extension: .txt
How to get file extension in Python?
In this article, we will cover How to extract file extensions using Python.
Contact Us