Pythonでファイル名に3桁の連番を振りたい。
Formatの書式
'{0:03d}'format(変数)
要素を指定:0 …リストや辞書の0番目の要素
書式:03d …0を3桁までの10進数で並べる(例:000)
参考:
【Python入門】format関数で文字列の書き方
python.org
例えば一連のfor文から一部を抜き出して動作させるなら下記のようになる。
book_dict = {'title': 'titles', 'code': '9784295002086','i': 0}
title = book_dict['title']
num = book_dict['code']
i = 0
print('./book_{0}/code_{1}_{2:03d}.txt'.format(title, num, i+1))
#./book_titles/code_9784295002086_001.txt