pythonの文字列形式の戻り値を'67.67.%s.%s' % (str(j), str(i))
のように割り当てると、dictのキーに割り当ててdictのサブディックのキーに割り当てることとの間に矛盾が生じます。例えばPythonの文字列形式の戻り値の振る舞いの割り当てが一致しません
:この例では
i = 0
j = 1
dict_template = {"id": "1", "another_dict": {"value": "hello"}}
dict_list = []
for idx in list(range(2, 1002)):
new_dict = copy.copy(dict_template)
new_dict['id'] = 'obj_id_%s' % str(idx)
new_dict['another_dict']['value'] = '67.67.%s.%s' % (str(j), str(i))
dict_list.append(new_dict)
if i < 254:
i += 1
else:
j += 1
i = 1
、毎new_dict [ '別の'] [ '値']同じ文字列であっても、同一のIDを有することになります。 しかし、この行をnew_dict['another_dict']['value'] = '67.67.%s.%s' % (str(j), str(i))
からnew_dict["another_dict"] = '67.67.%s.%s' % (str(j), str(i))
に変更した場合、それぞれのnew_dict ["another_dict"]の値は異なります。
ところで私はPython 3.4.3を使用しています。