use os.path.splitext instead of rfind to get input file extension