[issue42379] Optional List Args Persist Across Objects

2020-11-16 Thread Steven D'Aprano
Steven D'Aprano added the comment: Hi Rose, this is a FAQ: https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects although it's also a feature that does cause beginners some trouble, see for example my comment here for more information: https://bugs.pyt

[issue42379] Optional List Args Persist Across Objects

2020-11-16 Thread Eric V. Smith
Eric V. Smith added the comment: This is defined behavior in the language, so it's not a bug. The "pythonic" way to deal with this is usually: def funct(self, array = None): if array is None: array = [] -- components: +Interpreter Core -ctypes nosy: +eric.smith resolutio

[issue42379] Optional List Args Persist Across Objects

2020-11-16 Thread Rose Ridder
Rose Ridder added the comment: Sorry, incorrect code pasted in. The full comment and code is below: When creating several objects in one program, if there are lists passed into functions as optional arguments, those lists are persistent across all objects. # -*- coding: utf-8 -*- class Obj:

[issue42379] Optional List Args Persist Across Objects

2020-11-16 Thread Rose Ridder
Rose Ridder added the comment: Including script explicitly: # -*- coding: utf-8 -*- class Obj: def __init__(self, num): self.num = num self.var = self.funct() def funct(self, array = []): print (array) array = [1,2,3] return array

[issue42379] Optional List Args Persist Across Objects

2020-11-16 Thread Rose Ridder
New submission from Rose Ridder : When creating several objects in one program, if there are lists passed into functions as optional arguments, those lists are persistent across all objects. -- components: ctypes files: PythonObjectListIssue.py messages: 381153 nosy: rosadenderon prior