I would like to set the formatting of a large integer in an fstring programmatically. Specifically, I have an integer that can span several orders of magnitude and I'd like to print it using the underscore "_" delimiter, e.g.
num = 123456789
print(f"number is {num:9_d}")
>>> number is 123_456_789 # this is ok
num = 1234
print(f"number is {num:9_d}")
>>> number is 1_234 # this has extra spaces due to hand-picking 9
How can I set the number preceding "_d" programmatically based on the number of digits in num? (Or in case I asked an XY question, how can I print the number with underscore delimiters and no extra spaces?)
{num:<9_d}, though this will leave trailing spaces on the right side.