all Python 3Byte sequencesfunction
bytearray.expandtabs
bytearray — padding
Replace tabs with spaces up to the next tab stop.
Syntax
ba.expandtabs(...)
This does not insert a fixed number of spaces per tab: it tracks the current column and pads up to the next multiple of tabsize (8 by default). The same \t therefore expands to a different number of spaces depending on how many bytes precede it on the line, and \n or \r reset the column counter. A new bytearray is returned; the original is untouched.
Examples
print(bytearray(b'a\tb').expandtabs(4)) # → bytearray(b'a b')
print(bytearray(b'a\tb').expandtabs()) # → bytearray(b'a b')
print(bytearray(b'1\t22\t333').expandtabs(4).decode()) # → 1 22 333
print(bytearray(b'ab\tc').expandtabs(4)) # → bytearray(b'ab c')
print(bytearray(b'abc').expandtabs(4)) # → bytearray(b'abc')
See also
Open in the full glossarydocs.python.orgReport an inaccuracy