How to get the file extension in Python

To get the file extension in python you can use the following snippet.

Sample Python

import os.path  
filePath = "C:\Users\Codesnippets\Desktop\testfolder\test.bat"
print os.path.splitext(filePath)[1]

Please Share us:
Please rate this snippet

2 thoughts on “How to get the file extension in Python

Leave a Reply