import os path='file.txt' file=os.path.splitext(path) filename,type=file print(filename) print(type)