range with variable leading zeros
alex23
wuwei23 at gmail.com
Fri May 9 00:04:39 EDT 2008
On May 9, 1:42 pm, yhvh <yhvh2... at googlemail.com> wrote:
> I want to generate a range with variable leading zeros
>
> x = [0010, 0210]
> padding = len(x[1])
>
> for j in range(x[0], x[1]):
> print (url).join('%0(pad)d(jj)'+'.jpg') %{'pad':padding, 'jj':j}
>
> This is syntactically incorrect, you can't insert a variable into the
> string format options. Any ideas?
Concatenate the parts of the pattern string first:
pat = '%0' + str(padding) + 'd'
More information about the Python-list
mailing list