Python Get File Extension from Filename Example
This tutorial is focused on python get file extension from filename. you can understand a concept of python get file extension from path. let’s discuss about python get filename extension from path. it's simple example of how to get file extension in python. You just need to some step to done how to get file extension from path python.
In this example, I will give you a simple example of getting the file extension from file path. so let's see a simple example with output.
You can use these examples with python3 (Python 3) version.
Example:
main.py
import os fileName, fileExtension = os.path.splitext('/images/demo.png') print("File Name: ", fileName) print("File Extension: ", fileExtension)
Output:
File Name: /images/demo File Extension: .png
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Python Get First Date of Next Month Example
- Python Create Zip Archive from Directory Example
- Python List All Dates Between Two Dates Example
- How to Compare Two Dates in Python?
- How to Check if Today is Sunday or not in Python?
- How to Add Minutes to DateTime in Python?
- Python POST Request with Parameters Example
- How to Get Tomorrow Date in Python?
- How to Get Current Minute in Python?
- How to Get Current Hour in Python?
- How to Get Current Year in Python?