Problem with string parsing

Thomas Guettler guettli at thomas-guettler.de
Tue Oct 5 10:47:56 EDT 2004


Am Tue, 05 Oct 2004 07:38:09 -0700 schrieb Mike Howard:

> If I do this:
> string.lstrip('1_mature_dt=10-May-2002','1_mature_dt=')
> I get:
> '0-May-2002'
> Which I did not expect

Hi,

from the doc:
"""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"""

the second argument is a *list* of characters. Since "1" is
in the list, if gets stripped from "10-May", too.

You could use
mystring='1_mature_dt=10-May-2002'
mystart="1_mature_dt="
if mystring.startswith(mystart):
    mystring=mystring[len(mystart):]

BTW, you don't need the string-module. You can
use mystring.strip().

HTH,
 Thomas






More information about the Python-list mailing list