may be a bug in string.rstrip

Tyler Reguly ht at computerdefense.org
Fri Nov 23 05:41:57 CET 2007


Interesting... I tried this on three machines Windows/Python 2.4.3,
FC4/Python 2.4.3, Ubuntu/Python 2.5.1 and I saw the same thing for each...
It's apparently not a three character issue but rather related to specific
characters (e, n, o, r, t). A further test revealed that this affects one
additional character... the . (period/dot) character.

Here's what I did to test it:

for i in range(97,123):
 x = 'ab' + chr(i) + '.torrent'
 y = x.rstrip('.torrent')
 print ('Before: %s (%d)\tAfter: %s (%d)' % (x, len(x), y, len(y) ) )

Before: abcdefga.torrent (16)   After: abcdefga (8)
Before: abcdefgb.torrent (16)   After: abcdefgb (8)
Before: abcdefgc.torrent (16)   After: abcdefgc (8)
Before: abcdefgd.torrent (16)   After: abcdefgd (8)
Before: abcdefge.torrent (16)   After: abcdefg (7)
Before: abcdefgf.torrent (16)   After: abcdefgf (8)
Before: abcdefgg.torrent (16)   After: abcdefgg (8)
Before: abcdefgh.torrent (16)   After: abcdefgh (8)
Before: abcdefgi.torrent (16)   After: abcdefgi (8)
Before: abcdefgj.torrent (16)   After: abcdefgj (8)
Before: abcdefgk.torrent (16)   After: abcdefgk (8)
Before: abcdefgl.torrent (16)   After: abcdefgl (8)
Before: abcdefgm.torrent (16)   After: abcdefgm (8)
Before: abcdefgn.torrent (16)   After: abcdefg (7)
Before: abcdefgo.torrent (16)   After: abcdefg (7)
Before: abcdefgp.torrent (16)   After: abcdefgp (8)
Before: abcdefgq.torrent (16)   After: abcdefgq (8)
Before: abcdefgr.torrent (16)   After: abcdefg (7)
Before: abcdefgs.torrent (16)   After: abcdefgs (8)
Before: abcdefgt.torrent (16)   After: abcdefg (7)
Before: abcdefgu.torrent (16)   After: abcdefgu (8)
Before: abcdefgv.torrent (16)   After: abcdefgv (8)
Before: abcdefgw.torrent (16)   After: abcdefgw (8)
Before: abcdefgx.torrent (16)   After: abcdefgx (8)
Before: abcdefgy.torrent (16)   After: abcdefgy (8)
Before: abcdefgz.torrent (16)   After: abcdefgz (8)



Before: aba.torrent (11)        After: aba (3)
Before: abb.torrent (11)        After: abb (3)
Before: abc.torrent (11)        After: abc (3)
Before: abd.torrent (11)        After: abd (3)
Before: abe.torrent (11)        After: ab (2)
Before: abf.torrent (11)        After: abf (3)
Before: abg.torrent (11)        After: abg (3)
Before: abh.torrent (11)        After: abh (3)
Before: abi.torrent (11)        After: abi (3)
Before: abj.torrent (11)        After: abj (3)
Before: abk.torrent (11)        After: abk (3)
Before: abl.torrent (11)        After: abl (3)
Before: abm.torrent (11)        After: abm (3)
Before: abn.torrent (11)        After: ab (2)
Before: abo.torrent (11)        After: ab (2)
Before: abp.torrent (11)        After: abp (3)
Before: abq.torrent (11)        After: abq (3)
Before: abr.torrent (11)        After: ab (2)
Before: abs.torrent (11)        After: abs (3)
Before: abt.torrent (11)        After: ab (2)
Before: abu.torrent (11)        After: abu (3)
Before: abv.torrent (11)        After: abv (3)
Before: abw.torrent (11)        After: abw (3)
Before: abx.torrent (11)        After: abx (3)
Before: aby.torrent (11)        After: aby (3)
Before: abz.torrent (11)        After: abz (3)


On 11/22/07, kyo guan <kyoguan at gmail.com> wrote:
>
> Hi :
>
>         Please look at this code:
>
> >>> 'exe.torrent'.rstrip('.torrent')
> 'ex'                    <-----  it should be 'exe', why?
>
> but this is a right answer:
>
> >>> '120.exe'.rstrip('.exe')
> '120'                   <------ this is a right value.
>
>         there is a bug in the rstrip, lstrip there isn't this problem.
>
>
>
> Kyo.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071122/e02e499e/attachment.html>


More information about the Python-list mailing list