Message361407
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. |
|
Date |
User |
Action |
Args |
2020-02-05 06:35:54 | Kevin Young | set | recipients:
+ Kevin Young |
2020-02-05 06:35:54 | Kevin Young | set | messageid: <1580884554.4.0.0450040370405.issue39556@roundup.psfhosted.org> |
2020-02-05 06:35:54 | Kevin Young | link | issue39556 messages |
2020-02-05 06:35:53 | Kevin Young | create | |
|