I'm writing some reports, and I'd like to know if there's a simpler way to obtain the following behavior.
>>> '{:-^60}'.format('Percentage used: {:.2%}'.format(.4))
'------------------Percentage used: 40.00%-------------------'
As you can see I'm centering the text and then printing a number formated to percentage. But I'm using a format function inside another. If possible I'd like to do the same in a single function, kind of the following.
'$SOMETHING GOES HERE'.format(header = 'Percentage Used:',percentage = .4)
Of course I'm looking for a general solution, that would work with all, or most, of the formating options, not just to alignment
Thanks.
A more readable option might be str.center
>>> 'Percentage used: {:.2%}'.format(.4).center(60, '-')
'------------------Percentage used: 40.00%-------------------'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With