I know I can count the leading spaces in a string with this:
>>> a = \" foo bar baz qua \\n\"
>>> print \"Leading spaces\", len(a) - le
Just for variety, you could theoretically use regex. It's a little shorter, and looks nicer than the double call to len().
>>> import re
>>> a = " foo bar baz qua \n"
>>> re.search('\S', a).start() # index of the first non-whitespace char
3
Or alternatively:
>>> re.search('[^ ]', a).start() # index of the first non-space char
3
But I don't recommend this; according to a quick test I did, it's much less efficient than len(a)-len(lstrip(a)).