For example, if I have lots of lines of coding doing something like:
print('{:=+5d}'.format(my_value))
or perhaps something more involved like:
print('{:04d}-{:04d}|{:03d}'.format(val1, val2, val3))
Is there a good way (and is it good practice) to replace the string format conversion specifier with something so that I:
- Reduce the number of times that needs to be typed out
- Make it more human readable
- Make the format string parametric so it can be changed in one place
Edit for more clarity:
- These prints occur throughout the code and aren't just a single list of items in one spot I can loop through. The formats are also used for strings in log messages and other non-print places.
- I might want to even specify the string format programmatically
- This is running on a legacy python 2 script