Could someone explain this to a newbie

Discussion in 'Python' started by Sean Berry, Apr 27, 2004.

  1. Sean Berry

    Sean Berry Guest

    text = 'zone "" {''" {'

    This is expected.

    '" {'

    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 Berry, Apr 27, 2004
    1. Advertisements

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

    Michael Geary, Apr 27, 2004
    1. Advertisements

  3. Am Dienstag, 27. April 2004 19:45 schrieb Sean Berry:
    From the Python Manual:


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


    Heiko Wundram, Apr 27, 2004
  4. Maybe the docs ought to state that the method stops once it hits a
    char not in the *set* the passed string represents.
    Tor Iver Wilhelmsen, Apr 28, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.