1

I'm trying to write part of a logging function. As part of that I'm coding a function to print a formatted dictionary in the form:

key        : value
key1       : value
key63535   : value

to accommodate keys of different length while keeping alignment I'm using a left justified format string:

f"{key_string:<20}: {value}"

However, I would like to change this so the width can be varied (as small widths don't fit long strings and long widths make things more difficult to read with short strings). I expected this would be a simple matter of changing the 20 to var but to my surprise python doesn't seem to support this. Could you please let me know how to achieve this?

Thanks.

Pioneer_11
  • 670
  • 4
  • 19

0 Answers0