10}'.format(a)) # output: text b = "\x1...">

Line alignment does not work with ansi colors

Before this question with Python:

a = "text"
print('{0:>10}'.format(a))
# output:      text
b = "\x1b[33mtext\x1b[0m"
print('{0:>10}'.format(b))
# output: text

As you can see, the excuse right stopped working as soon as the coloring tags are added to the text. The second "text" should be indented as the first, but it is not.

+4
source share
1 answer

This is to be expected, because the data is already longer than your field width:

>>> len(b)
13
>>> len('{0:>10}'.format(b))
13

To see a workaround, check here: Printed string length in python (specifically a response from a Dawg user )

+2
source

Source: https://habr.com/ru/post/1693713/


All Articles