mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Add function to expand tabs.
This commit is contained in:
parent
cb7ce349e2
commit
6ff2e90c51
2 changed files with 26 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue