Is a list static when it's a class member?
Tom Plunket
tomas at fancy.org
Thu Oct 12 14:42:10 EDT 2006
Fredrik Lundh wrote:
> so what's the practical difference between
>
> def __init__(self, name):
> self.name = name
> self.data = []
>
> and
>
> def __init__(self, name):
> self.name = name
> self.data=[]
Ignoring nerd-extreme-pedantic-mode for this circumstance, you elided
the bits that were functionally different.
IOW, based on the OP's post, it appeared that C++ was infecting their
Python, and removing the class attributes entirely was likely what the
OP actually wanted.
> > In Python, you don't define the instance members in the class scope
> > like the OP has done:
>
> the OP's approach works perfectly fine, as long as you understand that
> class attributes are shared.
Obviously, as is "sticking a gun in your mouth is perfectly fine, as
long as you understand that pulling the trigger will yield a large
hole in the back of your skull." My reading of the OP's post was that
shared attributes were not desired.
-tom!
More information about the Python-list
mailing list