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? Hear, hear! Marko -- https://mail.python

Re: default argument value is mutable

2016-10-07 Thread ast
"jmp" a écrit dans le message de news:mailman.213.1475849391.30834.python-l...@python.org... On 10/07/2016 03:45 PM, ast wrote: "jmp" a écrit dans le message de news:mailman.210.1475844513.30834.python-l...@python.org... On 10/07/2016 02:07 PM, ast wrote: "jmp" a écrit dans le message d

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 http://www.Vex.Net/ IM:da.

Re: default argument value is mutable

2016-10-07 Thread jmp
On 10/07/2016 03:45 PM, ast wrote: "jmp" a écrit dans le message de news:mailman.210.1475844513.30834.python-l...@python.org... On 10/07/2016 02:07 PM, ast wrote: "jmp" a écrit dans le message de news:mailman.209.1475841371.30834.python-l...@python.org... On 10/07/2016 01:38 PM, Daiyue Wen

Re: default argument value is mutable

2016-10-07 Thread ast
"jmp" a écrit dans le message de news:mailman.210.1475844513.30834.python-l...@python.org... On 10/07/2016 02:07 PM, ast wrote: "jmp" 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 f

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 dirt

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 it? The usual way to avoid tha

Re: default argument value is mutable

2016-10-07 Thread jmp
On 10/07/2016 02:07 PM, ast wrote: "jmp" 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 some variables from

Re: default argument value is mutable

2016-10-07 Thread ast
"jmp" 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 some variables from one call of a function to an other

Re: default argument value is mutable

2016-10-07 Thread ast
"Daiyue Weng" 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 is mutable, what does it mean? and how

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(a=[])