On Nov 28, 3:04 pm, Mel <[EMAIL PROTECTED]> wrote:
> Paul Rudin wrote:
> > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> > A common paradigm to get round this - assuming you want a different
> > empty list each time - is something like:
>
> > def __init__(self, v = None):
> > self.values =
Paul Rudin wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> A common paradigm to get round this - assuming you want a different
> empty list each time - is something like:
>
> def __init__(self, v = None):
> self.values = v if v else []
>
> (or maybe test explicitly for None, but y
Paul Rudin <[EMAIL PROTECTED]> wrote:
> You have to understand that the default value for v - an empty list -
> is made at compile time
Not at compile time: the default value is created at runtime when the def
statement is executed.
--
http://mail.python.org/mailman/listinfo/python-list
On Nov 28, 7:19 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hello everybody,
>
> I've banged my ahead around for a while trying to figure out why
> multiple instances of a class share the same instance variable. I've
> stripped down my code to the following, which reproduces my proble
On Nov 28, 3:31 am, Paul Rudin <[EMAIL PROTECTED]> wrote:
> You have to understand that the default value for v - an empty list -
> is made at compile time - and it's the *same* list every time it's
> used i.e. if you don't pass in a value for v when you make new
> instances of your class.
*smack*
[EMAIL PROTECTED] wrote:
> Hello everybody,
>
> I've banged my ahead around for a while trying to figure out why
> multiple instances of a class share the same instance variable. I've
> stripped down my code to the following, which reproduces my problem.
>
This is a *feature* of Python tha
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> Hello everybody,
>
> I've banged my ahead around for a while trying to figure out why
> multiple instances of a class share the same instance variable. I've
> stripped down my code to the following, which reproduces my problem.
>
> class Test(