I often find myself in a need of stripping only a specified amount of characters from a string (most commonly a single character). I have been implementing this in an ad-hoc manner, which is quite inelegant:
def rstrip1(txt, chars):
if txt is None:
return None
elif any(txt.endswith(c) for c in chars):
return txt[:-1]
else:
return txt