diff options
Diffstat (limited to 'Lib/string.py')
-rw-r--r-- | Lib/string.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/string.py b/Lib/string.py index f7d4af6..cfb977f 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -143,3 +143,16 @@ def zfill(x, width): if s[0] in ('-', '+'): sign, s = s[0], s[1:] return sign + '0'*(width-n) + s + +# Expand tabs in a string. +# Doesn't take non-printing chars into account, but does understand \n. +def expandtabs(s, tabsize): + res = line = '' + for c in s: + if c == '\t': + c = ' '*(tabsize - len(line)%tabsize) + line = line + c + if c == '\n': + res = res + line + line = '' + return res + line |