I face this peculiar situation:
I am using str format to give my filenames a certain pattern. For example I am using a prefix and then a fixed-length number to create the filename. The problem occurred when I needed to also control the fixed-length number length:
prefix = 'action1'
n = 6
for i in range(0, 6):
filename = '{}_{:06}.jpg'.format(prefix, i)
print(filename)
action1_000000.jpg
action1_000001.jpg
...
I came up with this idea which combines old and new style string formatting but it's peculiar and surely prone to being deprecated:
n = 4
for i in range(0, 6):
filename = ('{}_{:0%d}.jpg' % n).format(prefix, i)
print(filename)
action1_0000.jpg
action1_0001.jpg
...
So, is there any other approach to control the string format (the :06 part) inside a string format ({}_{:06}.jpg)?