Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Could someone explain this to a newbie

Reply
Thread Tools

Could someone explain this to a newbie

 
 
Sean Berry
Guest
Posts: n/a
 
      04-27-2004
>>> text = 'zone "southernpine.com" {'
>>> text.lstrip("zone \"")

'southernpine.com" {'

This is expected.


>>> text = 'zone "newsouthpine.com" {'
>>> text.lstrip("zone \"")

'wsouthpine.com" {'

This is not.

What happened to the ne...

I suppose that is the secret, because I have
tried with other words beginning with ne and
they do not work either.

--
 
Reply With Quote
 
 
 
 
Michael Geary
Guest
Posts: n/a
 
      04-27-2004
Sean Berry wrote:
> >>> text = 'zone "southernpine.com" {'
> >>> text.lstrip("zone \"")

> 'southernpine.com" {'
>
> This is expected.
>
>
> >>> text = 'zone "newsouthpine.com" {'
> >>> text.lstrip("zone \"")

> 'wsouthpine.com" {'
>
> This is not.
>
> What happened to the ne...
>
> I suppose that is the secret, because I have
> tried with other words beginning with ne and
> they do not work either.


Sean, try this:

>>> text = 'abcabcaabbccaaabbbcccxyz'
>>> text.lstrip('abc')

'xyz'
>>>


Do you see what lstrip() really does now?

Your confusion is understandable. The documentation for lstrip() is very
poor--it does not make it at all clear what the function does. The argument
to lstrip() isn't a string that the function strips off, it is a *set of
characters* (expressed as a string) to strip off.

-Mike


 
Reply With Quote
 
 
 
 
Heiko Wundram
Guest
Posts: n/a
 
      04-27-2004
Am Dienstag, 27. April 2004 19:45 schrieb Sean Berry:
> >>> text = 'zone "newsouthpine.com" {'
> >>> text.lstrip("zone \"")

>
> 'wsouthpine.com" {'
>


From the Python Manual:

""
lstrip([chars])

Return a copy of the string with leading characters removed. If chars is
omitted or None, whitespace characters are removed. If given and not None,
chars must be a string; the characters in the string will be stripped from
the beginning of the string this method is called on. Changed in version
2.2.2: Support for the chars argument.
""

Thus, it does exactly as it sais. The first few characters after the "zone \""
in the string are contained in the chars array which you pass in (namely
"ne"), and thus they are also stripped from the string.

What you might want to do is something like the following:

x = x.strip()
if x.startswith("zone \""): x = x[6:]

HTH!

Heiko.

 
Reply With Quote
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      04-28-2004
Heiko Wundram <(E-Mail Removed)> writes:

> in the string are contained in the chars array which you pass in (namely
> "ne"), and thus they are also stripped from the string.


Maybe the docs ought to state that the method stops once it hits a
char not in the *set* the passed string represents.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Could someone please explain me this error? Alexander Mahone C Programming 5 05-05-2008 12:57 PM
vlan speed issue, could someone explain gentouru Cisco 0 03-06-2008 01:54 AM
Could someone please explain?! jignasuk@gmail.com C++ 5 01-10-2006 10:43 PM
Could someone explain some code? Gactimus C++ 22 12-15-2004 07:41 PM
Could someone explain these registry items that ad-aware found? systemtool Computer Support 16 05-08-2004 09:45 PM



Advertisments