ItSolutionStuff.com

Python Get File Extension from Filename Example

By Hardik Savani β€’ October 30, 2023
Python

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...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

Python Get First Date of Next Month Example

Read Now β†’
β˜…

Python Create Zip Archive from Directory Example

Read Now β†’
β˜…

Python List All Dates Between Two Dates Example

Read Now β†’
β˜…

How to Compare Two Dates in Python?

Read Now β†’
β˜…

How to Check if Today is Sunday or not in Python?

Read Now β†’
β˜…

How to Add Minutes to DateTime in Python?

Read Now β†’
β˜…

Python POST Request with Parameters Example

Read Now β†’
β˜…

How to Get Tomorrow Date in Python?

Read Now β†’
β˜…

How to Get Current Minute in Python?

Read Now β†’
β˜…

How to Get Current Hour in Python?

Read Now β†’
β˜…

How to Get Current Year in Python?

Read Now β†’