New submission from Kevin Young <kings...@gmail.com>:
Test code: class Test(object): def __init__(self, a={}): self._a = a def put(self, k, v): self._a[k] = v if __name__ == '__main__': t1 = Test() t1.put('aa', '11') t1.put('bb', '22') t2 = Test() t2.put('cc', '33') for k, v in t2._a.items(): print(k, '=', v) Output: aa = 11 bb = 22 cc = 33 The expected output should be: cc = 33 My workaround: self._a = dict(a) I have tested on both Python 3.7.3 and 3.8.1, they share the same results. I'm not sure if this is a bug or on-purpose feature of python. Could someone provide some guidance for me? Thank you. ---------- components: Interpreter Core messages: 361407 nosy: Kevin Young priority: normal severity: normal status: open title: Different objects of the same class references the same dictionary versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39556> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com