jdhunter at ace.bsd.uchicago.edu
Mon Sep 22 23:33:47 CEST 2003
>>>>> "Hank" == Hank <soundwave56 at yahoo.ca> writes:
Hank> The last 't' was stripped. Is this fixed or documented
Hank> anywhere? it works for other cases, but this one seems to
Hank> give me a weird result.
That's because rstrip removes any characters up until the first one
one that doesn't match. Since the 't' before the '.' is in the strip
string '.txt' it is stripped too. Does this example clarify:
>>> 'John D. Hunter'.rstrip('retD')
'John D. Hun'
If you want to remove the extension, the best way is to use splitext
>>> import os
>>> base, ext = os.path.splitext('test.txt')
Hope this helps,
More information about the Python-list