I have a variable line_number_max_digits and I want to use it in string format specification as width token. I have come up with the following code:
print ('{0:>%d}: {1}' % line_number_max_digits).format(lineno + i, chunk)
But I understand that percent formatting will eventually go away from Python. I could use string.Template or use format two times but it would make my code less clear:
print ('{{0:>{0}}}: {{1}}').format(line_number_max_digits).format(lineno + i, chunk)
Which way is considered a good practice in such situations?
There is a limited nesting support.
Example