You can use this expression to obtain the directory name seq0010
from the input 1
:
dirName = 'seq%03d0' % 1
Replace 1
with i
and you're set.
Frage
I'm trying to find how to create sequential directories with specific padding. For a given number it should create directories:
def createDirectories(number=10, name='seq'):
for i in range(1, number+1):
os.mkdir(name+i)
But it should produce directories in following naming convention
seq0010
seq0020
seq0030
...
seq0100
How to format numbers in that way?
Lösung 2
You can use this expression to obtain the directory name seq0010
from the input 1
:
dirName = 'seq%03d0' % 1
Replace 1
with i
and you're set.
Andere Tipps
>>> myNum = '5'
>>> print myNum.zfill(3)
>>> '005'
You can also use string formatting to create the entire folder name at once:
>>> 'seq{0:03d}0'.format(3)
'seq0030'