Add function to expand tabs.

This commit is contained in:
Guido van Rossum 1992-03-27 15:13:31 +00:00
parent cb7ce349e2
commit 6ff2e90c51
2 changed files with 26 additions and 0 deletions

View file

@ -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