may be a bug in string.rstrip

K

kyo guan

Hi :

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.



Kyo.
 
R

rzed

Hi :

Please look at this code:

'ex' <----- it should be 'exe', why?

It really shouldn't be.
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.

It's not a bug, but a misunderstanding of the way the function
works.

The argument you pass to strip, lstrip or rstrip is a character or
collection of characters to trim from the end of a string. You
would get the same results from: "120.exe".rstrip('.ex') or
"120.exe".rstrip('x.e') or
"120.exe".rstrip('ab.cdefghijklmnopqrstuvwxyz')

In other words, by passing ".torrent" as an argument, you cause
the function to remove and of the characters in this set: [.toren]
from the end of the string. Not surprisingly, it did remove
".torrent", but also the trailing 'e' from 'exe'. Since 'x' is not
in that set of characters, the function stopped there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top