[issue18127] Strange behaviour with default list argument

2013-06-03 Thread Barry A. Warsaw

Barry A. Warsaw added the comment:

While it's true that it can be confusing to users, it's not a bug.

http://docs.python.org/2/reference/compound_stmts.html#function

and a nice treatise on the subject by the Effbot:

http://effbot.org/zone/default-values.htm

--
nosy: +barry

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18127] Strange behaviour with default list argument

2013-06-03 Thread Eric V. Smith

Eric V. Smith added the comment:

It's by design. Search for "mutable default arguments", for example 
http://docs.python-guide.org/en/latest/writing/gotchas.html#mutable-default-arguments

--
nosy: +eric.smith
resolution:  -> invalid
stage:  -> committed/rejected
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18127] Strange behaviour with default list argument

2013-06-03 Thread Poul-Henning Kamp

New submission from Poul-Henning Kamp:

I'd like to nominate this piece of code as candidate for the next round of 
"Most unexpected python behaviour" awards:

def foo(a, x = []):
x.append(a)
return x

print(foo(1))
print(foo(2))

I expected the output to be:
[1]
[2]
but I get:
[1]
[1, 2]

Bug?  (If not, I'd *love* to read the rationale for this behaviour...)

--
messages: 190557
nosy: bsdphk
priority: normal
severity: normal
status: open
title: Strange behaviour with default list argument
type: behavior
versions: Python 2.7, Python 3.2

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com