[issue39556] Different objects of the same class references the same dictionary

2020-02-05 Thread Steven D'Aprano
Steven D'Aprano added the comment: Ammar: it is definitely a feature that default values are created only once, when the function is created, not over and over again every time the function is called. (These are sometimes called "early binding" and "late binding" respectively.) With early b

[issue39556] Different objects of the same class references the same dictionary

2020-02-04 Thread Kevin Young
Kevin Young added the comment: Thank you, Ammar! I thought the default values were locally scoped under the __init__() function. -- ___ Python tracker ___

[issue39556] Different objects of the same class references the same dictionary

2020-02-04 Thread Ammar Askar
Ammar Askar added the comment: This is a common mistake, you'll find the FAQ entry for it here: https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects It's not necessarily a "feature" but default values in functions are only created once, when the functi

[issue39556] Different objects of the same class references the same dictionary

2020-02-04 Thread Kevin Young
New submission from Kevin Young : 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',