To have specific number of digits in string formatting, I am aware that it can be done in this way:
In [18]: hours = 01
In [19]: "%.2d" %(hours)
Out[19]: '01'
In [20]: "%.2f" %(hours)
Out[20]: '1.00'
But my case is a bit different. I am using specific keys to denote the values, for example:
for filename in os.listdir('/home/user/zphot_01/')
Here I want to have different values for the '01'
, i.e.
for filename in os.listdir('/home/user/zphot_{value1}/'.format(value1=some_number):
When I use the above method with some_number = 01
, it does not take into account the 0
and so my folder is not recognised.
EDIT:
Most of the answers are for only one value, however, I want to have more than one key value, i.e.:
for filename in os.listdir('/home/user/zphot_{value1}/zphot_{value2}'.format(value1=some_number1,value2=some_number2)).