Grab a line's whitespace/indention with Python
Basically, if I have a line of text which starts with indention, what's the best way to grab that indention and put it into a variable in Python? For example, if the line is: \t\tthis line has two tabs of indention Then it would return '\t\t'. Or, if the line was: this line has four spaces of indention Then it would return four spaces. So I guess you could say that I just need to strip everything from a string from first non-whitespace character to the end. Thoughts? import re s = "\t\tthis line has two tabs of indention" re.match(r"\s*", s).group() // "\t\t" s = " this line has four spaces of