Could someone explain this to a newbie

S

Sean Berry

text = 'zone "southernpine.com" {''southernpine.com" {'

This is expected.

'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.

--
 
M

Michael Geary

Sean said:
'southernpine.com" {'

This is expected.


'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:

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
 
H

Heiko Wundram

Am Dienstag, 27. April 2004 19:45 schrieb Sean Berry:
'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.
 
T

Tor Iver Wilhelmsen

Heiko Wundram said:
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.
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top