Re: def X(l=[]): weirdness. Python bug ?

2008-08-28 Thread Andrew Lee
Bart van Deenen wrote: Hi all. I've stumbled onto a python behavior that I don't understand at all. Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) # function def X(l=[]): l.append(1) print l # first call of X X() [1] #second call of X X() [1, 1] Where does the list parameter 'l'

Re: def X(l=[]): weirdness. Python bug ?

2008-08-23 Thread Fredrik Lundh
Bart van Deenen wrote: I've stumbled onto a python behavior that I don't understand at all. http://effbot.org/zone/default-values.htm Is this correct behavior or is it a Python bug? Python's been out there for nearly 20 years. I think you safely can assume that if this really was a bug,

def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread Bart van Deenen
Hi all. I've stumbled onto a python behavior that I don't understand at all. Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) # function def X(l=[]): l.append(1) print l # first call of X X() [1] #second call of X X() [1, 1] Where does the list parameter 'l' live between the two

Re: def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread cokofreedom
On Aug 22, 11:13 am, Bart van Deenen [EMAIL PROTECTED] wrote: Hi all. I've stumbled onto a python behavior that I don't understand at all. Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) # function def X(l=[]):    l.append(1)    print l # first call of X X() [1] #second call of X

Re: def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread Wojtek Walczak
On Fri, 22 Aug 2008 11:13:52 +0200, Bart van Deenen wrote: I've stumbled onto a python behavior that I don't understand at all. ... Does anyone have any pointers to the language documentation where this behavior is described? Yes, it's documented in FAQ:

Re: def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread Bart van Deenen
Hi Thanks all for your answers. I figured your solution already, but now I understand where the behavior is from. One question remains: can I find my parameter 'l' somewhere? I looked in a lot of objects, but couldn't find it. Thanks Bart. [EMAIL PROTECTED] wrote: On Aug 22, 11:13 am,

Re: def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread Diez B. Roggisch
Wojtek Walczak schrieb: On Fri, 22 Aug 2008 11:13:52 +0200, Bart van Deenen wrote: I've stumbled onto a python behavior that I don't understand at all. ... Does anyone have any pointers to the language documentation where this behavior is described? Yes, it's documented in FAQ:

Re: def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread Bruno Desthuilliers
Bart van Deenen a écrit : (ot : please don't top post - corrected) [EMAIL PROTECTED] wrote: On Aug 22, 11:13 am, Bart van Deenen [EMAIL PROTECTED] wrote: # function def X(l=[]): l.append(1) print l # first call of X X() [1] #second call of X X() [1, 1] Where does the list parameter 'l'

Re: def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread Wojtek Walczak
On Fri, 22 Aug 2008 11:41:18 +0200, Bart van Deenen wrote: Thanks all for your answers. I figured your solution already, but now I understand where the behavior is from. One question remains: can I find my parameter 'l' somewhere? I looked in a lot of objects, but couldn't find it.

Re: def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread Wojtek Walczak
On Fri, 22 Aug 2008 11:42:03 +0200, Diez B. Roggisch wrote: It's amazing. I didn't analyse this properly, but IMHO this issue is the single most asked question (or rather the effects in produces) on this list. Maybe we should get *really* explicit in

Re: def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread Bart van Deenen
Diez B. Roggisch wrote: It's amazing. I didn't analyse this properly, but IMHO this issue is the single most asked question (or rather the effects in produces) on this list. I feel a bit dumb to ask a FAQ on the newsgroup. The problem with this particular question is that I found it hard to