os.path.splitext(file) code example Example: os path splitext import os basename, ext = os.path.splitext('inputfile.txt')