import glob, os
os.chdir("/mydir")
for file in glob.glob("*.txt"):
print(file)
>>> import os
>>> filename, file_extension = os.path.splitext('/path/to/somefile.ext')
>>> filename
'/path/to/somefile'
>>> file_extension
'.ext'
import os.path
extension = os.path.splitext(filename)[1]
import pathlib
print(pathlib.Path('yourPath.example').suffix) # '.example'
#or
import os
filename, file_extension = os.path.splitext('/path/to/somefile.ext')