Re: Default argument to __init__

2005-10-10 Thread Fredrik Lundh
"[EMAIL PROTECTED]" wrote: > Here's a piece of Python code and it's output. The output that Python > shows is not as per my expectation. Hope someone can explain to me this > behaviour: /snip/ > Why do myobj1.myarr and myobj2.myarr point to the same list? The > default value to __init__ for th

Re: Default argument to __init__

2005-10-10 Thread Larry Bates
This comes up on the list about once a week on this list. See: http://www.nexedi.org/sections/education/python/tips_and_tricks/python_and_mutable_n/view -Larry Bates [EMAIL PROTECTED] wrote: > Hi All: > > Here's a piece of Python code and it's output. The output that Python > shows is not as pe

Re: Default argument to __init__

2005-10-10 Thread Steve Holden
[EMAIL PROTECTED] wrote: > Hi All: > > Here's a piece of Python code and it's output. The output that Python > shows is not as per my expectation. Hope someone can explain to me this > behaviour: > > [code] > class MyClass: > def __init__(self, myarr=[]): > self.myarr = my

Re: Default argument to __init__

2005-10-10 Thread skip
vaibhav> Here's a piece of Python code and it's output. The output that vaibhav> Python shows is not as per my expectation. Hope someone can vaibhav> explain to me this behaviour: ... Yes, your default arg is evaluated once, at method definition time and shared betwee all instance

Default argument to __init__

2005-10-10 Thread netvaibhav
Hi All: Here's a piece of Python code and it's output. The output that Python shows is not as per my expectation. Hope someone can explain to me this behaviour: [code] class MyClass: def __init__(self, myarr=[]): self.myarr = myarr myobj1 = MyClass() myobj2 = MyClass() m