strip()
removes all the leading and trailing characters from the input string that match one of the characters in the parameter string:
>>> "abcdefabcdefabc".strip("cba")
'defabcdef'
You want to use a regex: table_name = re.sub(r"\.csv$", "", name)
or os.path
s path manipulation functions:
>>> table_name, extension = os.path.splitext("movies.csv")
>>> table_name
'movies'
>>> extension
'.csv'