I am trying to substitute a variable using format() and then format the resulting string using format().
This is what I ended up doing:
>>> '{:^50}'.format("Missing files for device : {0}".format(var))
' Missing files for device : abc '
where var is a variable holding 'abc'. Is there a better way to get the same result?
In your case, there is a simpler way:
>>> "Missing files for device : {0}".format(var).center(50)
' Missing files for device : abc '
Calling format twice is not necessary here.
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