I have a program that prints some stuff in columns:
print("{: <7}{: <15}{: <75}{: <25}".format(sno, variable[1], variable[2], variable[3]))
Sometimes the values are too large or somewhat small, so I want to dynamically assign the spaces to the specific columns. So I loop through the stuff and get the maximum length of the string. Then I want to assign it to the number of spaces like this:
max = 10 #or any other integer which gets calculated dynamically.
print("{: <7}{: <15}{: <max}{: <25}".format(sno, variable[1], variable[2], variable[3]))
But this line gives me a ValueError: Invalid format specifier
Error.
Is there a better way to do this or do I have to hard-code the integer there?