Jason Tackaberry wrote:
> On Mon, 2008-03-17 at 15:42 +0100, Duncan Webb wrote:
>   
>> class A:
>>     def __init__(self, l=[]):
>>         self.l = l
>>     
>
> Note that this creates a default list for l only once at
> class-declaration time.  All instances of A will share this list.  This
> is a common python gotcha.  You might want instead:
>
>         class A:
>            def __init__(self, l=None):
>               self.l = l or []
>         
>
>   
>> This behaviour seems a bit strange, clearly list is class A is the same 
>> objects for both instances and I'm wondering if this is correct?
>>     
>
> Yes, it's expected behaviour.
>   


Thanks both Jason and James, it makes sense that the list is created 
when the method is first parsed, this is something that I need to watch 
out for. I guess that this is only a problem for mutable objects, so 
strings and numbers are not a problem.

Duncan

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-devel mailing list
Freevo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freevo-devel

Reply via email to