may be a bug in string.rstrip
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Nov 23 18:06:11 CET 2007
Scott SA a écrit :
> On 11/23/07, kyo guan (kyoguan at gmail.com) wrote:
>> Please look at this code:
>> 'ex' <----- it should be 'exe', why?
>> but this is a right answer:
>> '120' <------ this is a right value.
>> there is a bug in the rstrip, lstrip there isn't this problem.
> Since your error has been addressed, I'd like to offer a point not expressed by others (that I've seen yet).
> To perform this task, there are a couple of options i.e. string.replace:
> >>> string.replace('120.exe','.exe','')
> ... but it has a side-effect of mid-string replacements:
> >>> string.replace('123.exe.more','.exe','')
> or maybe:
> >>> if x[-4:] == '.exe':
> ... x[:-4]
> ... is functional, but not elegant i.e. quick 'n dirty esp. as one line.
> The better option, IMO, is probably to use regex.
You forgot at least the simplest solution:
More information about the Python-list