range with variable leading zeros
Dan Bishop
danb_83 at yahoo.com
Thu May 8 23:54:59 EDT 2008
On May 8, 10:42 pm, yhvh <yhvh2... at googlemail.com> wrote:
> I want to generate a range with variable leading zeros
>
> x = [0010, 0210]
You do realize that this is octal, right?
> padding = len(x[1])
len is undefined for integers. Perhaps you meant "len(str(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?
You can, however, do this:
>>> '%0*d' % (5, 123)
'00123'
More information about the Python-list
mailing list