I am using Python 3 to process file names, and this is my code:
name = 'movies.csv' table_name = name.strip(".csv")
The expected value of table_name should be "movies" yet table_name keeps returning "movie".
Why is it doing this?
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With