Ich habe unter Code, Der Ausgang kommt sehr komisch.Warum wird mein Wörterbuch in Python nicht aktualisiert?
wsman_invoke_attr = {}
l = [u'BIOS.Setup.1-1:Slot3', u'BIOS.Setup.1-1:Slot2', u'BIOS.Setup.1-1:Slot1', u'BIOS.Setup.1-1:Slot5', u'BIOS.Setup.1-1:Slot4']
w = []
k = {"a":w}
for i in l:
wsman_invoke_attr["InstanceID"] = i
w.append([wsman_invoke_attr])
k["a"] = copy.deepcopy(w)
wsman_invoke_attr.clear()
print k
Der Ausgang kommt als {'a': [[{'InstanceID': u'BIOS.Setup.1-1:Slot4'}], [{'InstanceID': u'BIOS.Setup.1-1:Slot4'}], [{'InstanceID': u'BIOS.Setup.1-1:Slot4'}], [{'InstanceID': u'BIOS.Setup.1-1:Slot4'}], [{'InstanceID': u'BIOS.Setup.1-1:Slot4'}]]}
wo, wie ich für
{'a': [[{'InstanceID': u'BIOS.Setup.1-1:Slot3'}], [{'InstanceID': u'BIOS.Setup.1-1:Slot4'}], [{'InstanceID': u'BIOS.Setup.1-1:Slot2'}], [{'InstanceID': u'BIOS.Setup.1-1:Slot5'}], [{'InstanceID': u'BIOS.Setup.1-1:Slot1'}]]}
Wo ist es schief läuft suchen?
Das "Fix" für den Code ersetzt 'k [" a "] = copy.deepcopy (w)' mit 'w = copy.deepcopy (w); k ["a"] = w ", aber die bessere Lösung ist die Umstrukturierung zu einem Listenverständnis nach Viraptor – zehnpaard