This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Overwritten (custom) uuid inside dictionary
Type: behavior Stage: resolved
Components: Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder: FAQ need list mutation answers
View: 20135
Assigned To: Nosy List: beta990, r.david.murray
Priority: normal Keywords:

Created on 2014-05-25 13:36 by beta990, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
1.py beta990, 2014-05-25 13:36 Source Code
Messages (3)
msg219090 - (view) Author: beta (beta990) Date: 2014-05-25 13:36
Results:
Block: 2d = {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 0} same as {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 0}
Block: 2e = {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 0} same as {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 0}
Block: 2f = {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 0} same as {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 0}
Block: 8c = {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 1} same as {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 1}
Block: 8d = {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 1} same as {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 1}
Block: 4e = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 2} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 2}
Block: 4f = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 2} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 2}
Block: 4g = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 2} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 2}
Block: 4h = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 2} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 2}
Block: 6d = {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 3} same as {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 3}
Block: 6e = {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 3} same as {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 3}
Block: d3 = {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 4} same as {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 4}
Block: d4 = {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 4} same as {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 4}
Block: d5 = {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 4} same as {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 4}
Block: 10h = {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5} same as {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5}
Block: 10i = {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5} same as {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5}
Block: 10j = {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5} same as {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5}
Block: j3 = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 6} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 6}
Block: j4 = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 6} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 6}
Block: j5 = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 6} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 6}
Block: j6 = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 6} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 6}
Block: 10d = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7}
Block: 10e = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7}
Block: 10f = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7}
Block: 10g = {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7} same as {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7}

Actually SetPositions = {} result:
{   '10d': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7},
    '10e': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7},
    '10f': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7},
    '10g': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7},
    '10h': {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5},
    '10i': {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5},
    '10j': {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5},
    '2d': {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5},
    '2e': {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5},
    '2f': {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5},
    '4e': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7},
    '4f': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7},
    '4g': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7},
    '4h': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7},
    '6d': {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 3},
    '6e': {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 3},
    '8c': {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 3},
    '8d': {'Blocks': 2, 'Name': 'Mijnenveger', 'uuid': 3},
    'd3': {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5},
    'd4': {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5},
    'd5': {'Blocks': 3, 'Name': 'Fregatten', 'uuid': 5},
    'j3': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7},
    'j4': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7},
    'j5': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7},
    'j6': {'Blocks': 4, 'Name': 'Kruiser', 'uuid': 7}}

uuid are overwritten, but where? It seems like a Python bug, but don't really know to be sure, so sorry if it isn't one.
msg219111 - (view) Author: beta (beta990) Date: 2014-05-25 23:24
import copy

ship = {'Name': 'Slagschip', 'Blocks': 5}

shipData = copy.deepcopy(ship) # needed, otherwise linked-object
shipData['uuid'] = Id # unique Id

Is this the correct Python behavior?
msg219655 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-06-03 02:31
In python, everything is references to objects.  So yes, this is expected Python behavior.  Issue 20135 is about improving the FAQ entries on this subject, so I'm closing this as a duplicate of that issue.
History
Date User Action Args
2022-04-11 14:58:04adminsetgithub: 65775
2014-06-03 02:31:16r.david.murraysetstatus: open -> closed

superseder: FAQ need list mutation answers
type: behavior

nosy: + r.david.murray
messages: + msg219655
stage: resolved
2014-05-25 23:24:47beta990setresolution: not a bug
messages: + msg219111
2014-05-25 13:36:49beta990create