473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2255
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".lstri p("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.c om> 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.c om> 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
2849
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
1547
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 = self.content.lstrip().rstrip() + " " + content FYI, you can just use the following, which is equivalent: self.content = self.content.strip() + u" " + content Notice...
12
16080
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 type. Now the problem is how to print the binary format of that charater to the standard output. It seems a common task but I just cannot find the...
4
3319
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 >>> t = 'D:\\music\\D\\' >>> print t D:\music\D\
4
2207
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 ' The names are analogous to strip, rstrip, and lstrip. But the functionality is basically this: def lchop(self, prefix):
3
3369
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
3126
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': u'8'} Thanks, Matthew
2
1880
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
2108
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: s2 = s.upper().lstrip(chars.upper()) return s else:
0
7502
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7434
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7791
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1045
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
744
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.