I\'m confused by how the length of a string is calculated when expandtabs is used. I thought expandtabs replaces tabs with the appropriate number of spaces (with the default
The tab increments the column pointer to the next multiple of 8:
>>> 'abc\tabc'.expandtabs().replace(' ', '*')
'abc*****abc'
Like when you are entering tabs in a text-editor, the tab character increases the length to the next multiple of 8.
So:
'\t'
by itself is 8, obviously.'\t\t'
is 16.'abc\tabc'
starts at 3 characters, then a tab pushes it up to 8, and then the last 'abc'
pushes it from 8 to 11...'abc\tabc\tabc'
likewise starts at 3, tab bumps it to 8, another 'abc'
goes to 11, then another tab pushes it to 16, and the final 'abc'
brings the length to 19.