Is it possible to use the python command rstrip so that it does only remove one exact string and does not take all letters separately?
rstrip
I was confused w
Define a helper function:
def strip_suffix(s, suf): if s.endswith(suf): return s[:len(s)-len(suf)] return s
or use regex:
import re suffix = ".txt" s = re.sub(re.escape(suffix) + '$', '', s)