Re: default argument value is mutable

2016-10-07 Thread Marko Rauhamaa
"D'Arcy J.M. Cain" : > On Fri, 07 Oct 2016 16:09:19 +0200 > jmp wrote: >> What about >> >> def test(): >>if not hasattr(test, '_store'): test._store={'x':0} >>test._store['x'] += 1 > > Why is everyone working so hard to avoid creating a class?

Re: default argument value is mutable

2016-10-07 Thread ast
thon.org... On 10/07/2016 02:07 PM, ast wrote: "jmp" <jeanmic...@sequans.com> a écrit dans le message de news:mailman.209.1475841371.30834.python-l...@python.org... On 10/07/2016 01:38 PM, Daiyue Weng wrote: So the rule of thumb for default argument value is "No mutabl

Re: default argument value is mutable

2016-10-07 Thread D'Arcy J.M. Cain
On Fri, 07 Oct 2016 16:09:19 +0200 jmp wrote: > What about > > def test(): >if not hasattr(test, '_store'): test._store={'x':0} >test._store['x'] += 1 Why is everyone working so hard to avoid creating a class? -- D'Arcy J.M. Cain System Administrator, Vex.Net

Re: default argument value is mutable

2016-10-07 Thread jmp
an.209.1475841371.30834.python-l...@python.org... On 10/07/2016 01:38 PM, Daiyue Weng wrote: So the rule of thumb for default argument value is "No mutable" Cheers, It can be used to store some variables from one call of a function to an other one. def test( _store={'x':0}):

Re: default argument value is mutable

2016-10-07 Thread ast
thon.org... On 10/07/2016 01:38 PM, Daiyue Weng wrote: So the rule of thumb for default argument value is "No mutable" Cheers, It can be used to store some variables from one call of a function to an other one. def test( _store={'x':0}): x = _store['x'] . do some stu

Re: default argument value is mutable

2016-10-07 Thread Steve D'Aprano
On Fri, 7 Oct 2016 11:48 pm, jmp wrote: > On 10/07/2016 02:07 PM, ast wrote: >> It can be used to store some variables from one call of >> a function to an other one. >> >> def test( _store={'x':0}): >> >> x = _store['x'] >> . do some stuff >>_store['x'] = x > > For personal

Re: default argument value is mutable

2016-10-07 Thread Steve D'Aprano
On Fri, 7 Oct 2016 10:38 pm, Daiyue Weng wrote: > Hi, I declare two parameters for a function with default values [], > > def one_function(arg, arg1=[], arg2=[]): > > PyCharm warns me: > > Default argument value is mutable, > > what does it mean? and how to fix i

Re: default argument value is mutable

2016-10-07 Thread jmp
On 10/07/2016 02:07 PM, ast wrote: "jmp" <jeanmic...@sequans.com> a écrit dans le message de news:mailman.209.1475841371.30834.python-l...@python.org... On 10/07/2016 01:38 PM, Daiyue Weng wrote: So the rule of thumb for default argument value is "No mutable"

Re: default argument value is mutable

2016-10-07 Thread ast
"jmp" <jeanmic...@sequans.com> a écrit dans le message de news:mailman.209.1475841371.30834.python-l...@python.org... On 10/07/2016 01:38 PM, Daiyue Weng wrote: So the rule of thumb for default argument value is "No mutable" Cheers, It can be used to store so

Re: default argument value is mutable

2016-10-07 Thread ast
"Daiyue Weng" <daiyuew...@gmail.com> a écrit dans le message de news:mailman.208.1475840291.30834.python-l...@python.org... Hi, I declare two parameters for a function with default values [], def one_function(arg, arg1=[], arg2=[]): PyCharm warns me: Default argument value i

Re: default argument value is mutable

2016-10-07 Thread jmp
On 10/07/2016 01:38 PM, Daiyue Weng wrote: Hi, I declare two parameters for a function with default values [], def one_function(arg, arg1=[], arg2=[]): PyCharm warns me: Default argument value is mutable, what does it mean? and how to fix it? cheers You'll run into this bug def foo

default argument value is mutable

2016-10-07 Thread Daiyue Weng
Hi, I declare two parameters for a function with default values [], def one_function(arg, arg1=[], arg2=[]): PyCharm warns me: Default argument value is mutable, what does it mean? and how to fix it? cheers -- https://mail.python.org/mailman/listinfo/python-list