[New-bugs-announce] [issue32712] Modifying a list/dict effects all variables sharing that address
64andy
report at bugs.python.org
Mon Jan 29 08:57:45 EST 2018
New submission from 64andy <64andy2000 at gmail.com>:
If multiple lists/dictionaries are in the same memory address (usually caused by var1 = var2), then altering one will effect every variable in that address.
The ways I've found to achieve this are:
>>> my_list[2] = "Spam"
>>> my_list += "9"
>>> my_list.insert(4, "Hello")
>>> dictvar.update({"Three": "Four"})
This was achieved using Python 3.6.4 32-bit and 3.6.3 64-bit (CPython), and happened in both IDLE and python.exe
List Example code:
x = ['a','b','c']
y = x #Now y and x share a memory address, because CPython does that
print(f"Sanity test - x and y share the same address = {x is y}")
y[1] = '123'
y += ["Foo"]
y.insert(-1, "Eleven")
#x's Expected Value: ['a','b','c']
print(x) #Actual Value
----------
messages: 311135
nosy: 64andy
priority: normal
severity: normal
status: open
title: Modifying a list/dict effects all variables sharing that address
type: behavior
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32712>
_______________________________________
More information about the New-bugs-announce
mailing list