On Wed, Jul 31, 2013 at 3:07 PM, Rotwang <sg...@hotmail.co.uk> wrote:
>> # Assumes spaces OR tabs but not both
>> # Can't see an easy way to count leading spaces other than:
>> # len(s)-len(s.lstrip())
>
>
> How about len(s.expandtabs()) - len(s.lstrip()) instead?

Still comes to the same thing. The only diff is that tabs get treated
as eight spaces instead of one (and the bug that a tab elsewhere in
the line will result in indentation, which is fixed by lstripping the
tab-expanded form). It won't perfectly round-trip with a mixture of
tabs and spaces; as it is, you can pick one or the other and run with
it. Anyway, the main point is that indentation will work. Sure you
might have ugly narrow code, but it'll run with one-space indents.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to