I find a bug in str.lstrip, when i call str.lstrip, i get this result. tiny➜ ~ python Python 2.7.5+ (default, Feb 27 2014, 19:37:08) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.
a='device_info' a.lstrip('device') '_info' a.lstrip('device_') 'nfo'
tiny➜ ~ uname -a Linux tinymint 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux tiny➜ ~
On Wed, Mar 11, 2015 at 4:27 AM, lou xiao <lox.xiao@gmail.com> wrote:
I find a bug in str.lstrip, when i call str.lstrip, i get this result.
tiny➜ ~ python Python 2.7.5+ (default, Feb 27 2014, 19:37:08) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.
a='device_info' a.lstrip('device') '_info' a.lstrip('device_') 'nfo'
tiny➜ ~ uname -a Linux tinymint 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux tiny➜ ~
It's not a bug, because it isn't doing what you think it is. It strips a *set of characters*, not a prefix string. https://docs.python.org/2/library/stdtypes.html#str.lstrip https://docs.python.org/3/library/stdtypes.html#str.lstrip ChrisA
ths, i misunderstood the method 2015-03-11 1:33 GMT+08:00 Chris Angelico <rosuav@gmail.com>:
On Wed, Mar 11, 2015 at 4:27 AM, lou xiao <lox.xiao@gmail.com> wrote:
I find a bug in str.lstrip, when i call str.lstrip, i get this result.
tiny➜ ~ python Python 2.7.5+ (default, Feb 27 2014, 19:37:08) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.
a='device_info' a.lstrip('device') '_info' a.lstrip('device_') 'nfo'
tiny➜ ~ uname -a Linux tinymint 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux tiny➜ ~
It's not a bug, because it isn't doing what you think it is. It strips a *set of characters*, not a prefix string.
https://docs.python.org/2/library/stdtypes.html#str.lstrip https://docs.python.org/3/library/stdtypes.html#str.lstrip
ChrisA
On Tue, Mar 10, 2015 at 2:27 PM, lou xiao <lox.xiao@gmail.com> wrote:
tiny➜ ~ python Python 2.7.5+ (default, Feb 27 2014, 19:37:08) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.
a='device_info' a.lstrip('device') '_info' a.lstrip('device_') 'nfo'
On one hand, this is the "development of python itself" list; this issue was more aimed to the general python list, of you was sure that this is a real bug, to the issue tracker. On the other hand, this is not a bug! If you pass a parameter to lstrip it will (quoted from its help) "remove characters in chars instead.", so the moment you pass "device_", it removes all those characers from the left... note that the 'i' is removed twice. Regards, -- . Facundo Blog: http://www.taniquetil.com.ar/plog/ PyAr: http://www.python.org/ar/ Twitter: @facundobatista
* lou xiao <lox.xiao@gmail.com> [2015-03-11 01:27:21 +0800]:
I find a bug in str.lstrip, when i call str.lstrip, i get this result.
You're misunderstanding how str.strip works. It takes a set of characters and removes them all from the beginning: >>> "abababcd".lstrip('ab') >>> 'cd' Florian -- http://www.the-compiler.org | me@the-compiler.org (Mail/XMPP) GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc I love long mails! | http://email.is-not-s.ms/
lou xiao writes:
I find a bug in str.lstrip, when i call str.lstrip, i get this result.
a.lstrip('device_') 'nfo'
Try a.lstrip('_ecived') You'll see that you get the same result. I suspect that you misunderstand the meaning of the argument, which is not a sequence of characters, but a *set* of characters.
participants (5)
-
Chris Angelico
-
Facundo Batista
-
Florian Bruhin
-
lou xiao
-
Stephen J. Turnbull