Python string.strip stripping too many characters [duplicate]

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.paths path manipulation functions:

>>> table_name, extension = os.path.splitext("movies.csv")
>>> table_name
'movies'
>>> extension
'.csv'

Leave a Comment