0

I'm using python formating to print some left aligned columns.

This nicely left alignes a, b and c:

out_string = '{:30} {:20} {:10}'.format(a, b, c)

Then I tried using constants, but failed with ValueError: Invalid format specifier:

ALIGNa = 30
ALIGNb = 20
ALIGNc = 10
out_string = '{:ALIGNa} {:ALIGNb} {:ALIGNc}'.format(a, b, c)

Why does it fail?

2
  • Is there any reason why you can't use an f-string? Commented Oct 19, 2022 at 7:23
  • You can find the explanation here. Try formatting with fstring- out_string = f'{a[:ALIGNa]} {b[:ALIGNb]} {c[:ALIGNc]}' Commented Oct 19, 2022 at 7:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.