C Barr Leigh a écrit :
Help! Have I found a serious bug?
No. This is a FAQ. Default arguments of functions are evaled only once -
when the def statement is eval'd and the function object constructed.
This seems like highly undesired behaviour to me.
Possibly, but this is unlikely to change
Gabriel Genellina typed:
See
http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm
Thanks for the link, Gabriel. I didn't know about this.
--
Ayaz Ahmed Khan
Falling in love makes smoking pot all day look like the ultimate in
restraint.
-- Dave Sim,
Help! Have I found a serious bug?
This seems like highly undesired behaviour to me. From the program
below, I get output:
call1: ['sdf']
call2: ['Set within test for call2']
call3: ['Set within test for call2']
instead of what I should get,
call1: ['sdf']
call2: ['Set within test for call2']
C Barr Leigh [EMAIL PROTECTED] writes:
Help! Have I found a serious bug?
This seems like highly undesired behaviour to me. From the program
below, I get output:
It is intentional, not a bug, see the docs. Whether it's desirable is
a different question.
--
En Wed, 07 Mar 2007 23:39:21 -0300, C Barr Leigh [EMAIL PROTECTED]
escribió:
Help! Have I found a serious bug?
Not at all! This is by design.
def testPersistence(anarg,twooption=[]):
#print anarg
if not twooption:
twooption.append('Set within test for '+anarg)
See
Paul Rubin wrote:
C Barr Leigh [EMAIL PROTECTED] writes:
Help! Have I found a serious bug?
This seems like highly undesired behaviour to me. From the program
below, I get output:
It is intentional, not a bug, see the docs. Whether it's desirable is
a different question.
True. It
John Nagle [EMAIL PROTECTED] writes:
True. It would make sense to disallow mutable values as
initial values for optional arguments. The present behavior is silly.
That would be the worst of both worlds. The main alternative to the
present behavior is re-computing the default value every
On Mar 7, 10:14 pm, John Nagle [EMAIL PROTECTED] wrote:
Paul Rubin wrote:
C Barr Leigh [EMAIL PROTECTED] writes:
Help! Have I found a serious bug?
This seems like highly undesired behaviour to me. From the program
below, I get output:
It is intentional, not a bug, see the docs. Whether
On Mar 7, 10:24 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
John Nagle [EMAIL PROTECTED] writes:
True. It would make sense to disallow mutable values as
initial values for optional arguments. The present behavior is silly.
That would be the worst of both worlds. The main
On Thu, 08 Mar 2007 03:14:53 +, John Nagle wrote:
Paul Rubin wrote:
C Barr Leigh [EMAIL PROTECTED] writes:
Help! Have I found a serious bug?
This seems like highly undesired behaviour to me. From the program
below, I get output:
It is intentional, not a bug, see the docs. Whether
Steven D'Aprano [EMAIL PROTECTED] writes:
def factorial(n, _cache={}):
try:
return _cache[n]
except KeyError:
There are other ways of implementing caches, but this is quick and easy
and works well for many functions.
I like this better (examples are untested):
def
Oh, oops! Of course... :) A great and sensible feature if you're
expecting it.
Thanks very much, everyone, for the links and discussion!
Chris
--
http://mail.python.org/mailman/listinfo/python-list
John Nagle wrote:
True. It would make sense to disallow mutable values as
initial values for optional arguments. The present behavior
is silly.
Why? You're free to only use immutables.
Regards,
Björn
--
BOFH excuse #42:
spaghetti cable cause packet failure
--
13 matches
Mail list logo