473,396 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Bug in string.lstrip?

Hello - has anyone else had trouble with string.lstrip stripping too
much? Here's what I get (Python 2.3.4):
import string
string.lstrip("test/one/two/a.b.c", "test/one/") 'wo/a.b.c' string.lstrip("test/one/two/a.b.c", "test/one") 'wo/a.b.c' string.lstrip("test/one/two/a.b.c", "test/one/tw") 'a.b.c'


Similar things happened with the strip() string method. Am I missing
something, or should I file a bug report?

Thanks,
Brian
Jul 18 '05 #1
3 2243
Brian wrote:
Hello - has anyone else had trouble with string.lstrip stripping too
much? Here's what I get (Python 2.3.4):
>>> import string
>>> string.lstrip("test/one/two/a.b.c", "test/one/") 'wo/a.b.c' >>> string.lstrip("test/one/two/a.b.c", "test/one") 'wo/a.b.c' >>> string.lstrip("test/one/two/a.b.c", "test/one/tw") 'a.b.c' >>>
Similar things happened with the strip() string method. Am I missing
something, or should I file a bug report?

Thanks,
Brian


I think lstrip() just removes the characters that are contained in the
second string. The order of characters in the second string is irrelevant.

For example..
"abcdefg".lstrip("bac" )

'defg'

Your examples are correct because it removes a run of any of the
characters contained in the seconds string.

Perhaps someone can explain this better than I can. ;)

Will McGugan
Jul 18 '05 #2
Brian <br***@nospam.com> writes:
Hello - has anyone else had trouble with string.lstrip stripping too
much? Here's what I get (Python 2.3.4):
>>> import string
>>> string.lstrip("test/one/two/a.b.c", "test/one/")

'wo/a.b.c'


The second argument of lstrip has a different meaning from what you
think it does --- see the library documentation for the string module
for details.

--
Brian Gough

Network Theory Ltd,
Publishing the Python Manuals --- http://www.network-theory.co.uk/python/
Jul 18 '05 #3
Brian <br***@nospam.com> writes:
Hello - has anyone else had trouble with string.lstrip stripping too
much? Here's what I get (Python 2.3.4):
>>> import string
>>> string.lstrip("test/one/two/a.b.c", "test/one/") 'wo/a.b.c' >>> string.lstrip("test/one/two/a.b.c", "test/one") 'wo/a.b.c' >>> string.lstrip("test/one/two/a.b.c", "test/one/tw") 'a.b.c' >>>


Similar things happened with the strip() string method. Am I missing
something, or should I file a bug report?


Strip considers the second parameter as a *set* of characters to
remove.

Cheers,
mwh

--
<dash> web in my head get it out get it out
-- from Twisted.Quotes
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Pete Jereb | last post by:
Python 2.3 (#46, Jul 29 2003, 18:54:32) on win32 >>> s = 'chg bonn_fee' >>> print s chg bonn_fee >>> print s.lstrip('chg ') bonn_fee >>> s = 'chg conn_fee'
0
by: Uche Ogbuji | last post by:
nikita_raja@yahoo.com (Sam Smith) wrote in message news:<b19beb92.0403051302.456e024f@posting.google.com>... > def characters(self, content): > self.content =...
12
by: neutrino | last post by:
Greetings to the Python gurus, I have a binary file and wish to see the "raw" content of it. So I open it in binary mode, and read one byte at a time to a variable, which will be of the string...
4
by: joram gemma | last post by:
Hello, on windows python 2.4.1 I have the following problem >>> s = 'D:\\music\\D\\Daniel Lanois\\For the beauty of Wynona' >>> print s D:\music\D\Daniel Lanois\For the beauty of Wynona >>>...
4
by: Andy | last post by:
What do people think of this? 'prefixed string'.lchop('prefix') == 'ed string' 'string with suffix'.rchop('suffix') == 'string with ' 'prefix and suffix.chop('prefix', 'suffix') == ' and ' ...
3
by: steve morin | last post by:
http://www.python.org/doc/2.4.1/lib/node110.html These methods are being deprecated. What are they being replaced with? Does anyone know? Steve
7
by: manstey | last post by:
Hi, How do I convert a string like: a="{'syllable': u'cv-i b.v^ y^-f', 'ketiv-qere': 'n', 'wordWTS': u'8'}" into a dictionary: b={'syllable': u'cv-i b.v^ y^-f', 'ketiv-qere': 'n', 'wordWTS':...
2
by: kyo guan | last post by:
Hi : Please look at this code: 'ex' <----- it should be 'exe', why? but this is a right answer: '120' <------ this is a right value.
2
by: Kelie | last post by:
Hello, Is there such a function included in the standard Python distribution? This is what I came up with. How to improve it? Thanks. def lstrip2(s, chars, ingoreCase = True): if ingoreCase:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.