How do I count the number of spaces at the left end of a string?

Daniel Nogradi nogradi at gmail.com
Wed May 16 17:43:05 EDT 2007


> I don't know exactly what the first non-space character is. I know the
> first non-space character will be  * or an alphanumeric character.

How about:

>>> mystring = '    ksjfkfjkfjds   '
>>> print len( mystring ) - len( mystring.lstrip( ) )
4


HTH,
Daniel



More information about the Python-list mailing list