Determine the file extension
os.path.splitext() is used to split the path name into a pair root and ext.
e.g. C:\Users\memyselfandi\projects\file_extension_test\data.csv
is split into C:\Users\memyselfandi\projects\file_extension_test\data and .csv
Here is a working snippet for identifying CSV and XLS:
import os
if os.path.isfile(input_file):
file_extension = os.path.splitext(input_file)[1].lower()
if file_extension == ".csv":
logger.info("It's a CSV")
# do something with CSV
elif file_extension == ".xls":
logger.info("It's an XLS")
# do something with XLS
else:
logger.error("No valid file extension")