Get Extension of File Path using Python

os.path.splitext function

import os.path

path = '/var/tmp/archived.tar.gz'
extension = os.path.splitext(path)[1]

print(extension)

Leave a Comment

Cancel reply

Your email address will not be published.