"[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
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
[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
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
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