Re: Is a list static when it's a class member?

2006-10-12 Thread Tom Plunket
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

Re: Is a list static when it's a class member?

2006-10-12 Thread Fredrik Lundh
Tom Plunket wrote: 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. in my experience, the you're not old enough to understand this approach to teaching usually means that the

Is a list static when it's a class member?

2006-10-10 Thread glue
I have a class with a list member and the list seems to behave like it's static while other class members don't. The code... class A: name = data = [] def __init__(self, name): self.name = name def append(self, info): self.data.append(info) def enum(self):

Re: Is a list static when it's a class member?

2006-10-10 Thread Tim Chase
class A: name = data = [] def __init__(self, name): self.name = name def append(self, info): self.data.append(info) def enum(self): for x in self.data: print \t%s % x How do i get: A: one two B: horse

Re: Is a list static when it's a class member?

2006-10-10 Thread Antoine De Groote
glue wrote: I have a class with a list member and the list seems to behave like it's static while other class members don't. The code... class A: name = data = [] def __init__(self, name): self.name = name def append(self, info): self.data.append(info)

Re: Is a list static when it's a class member?

2006-10-10 Thread kath
glue wrote: I have a class with a list member and the list seems to behave like it's static while other class members don't. The code... class A: name = data = [] def __init__(self, name): self.name = name def append(self, info): self.data.append(info)

Re: Is a list static when it's a class member?

2006-10-10 Thread Fredrik Lundh
glue wrote: I have a class with a list member and the list seems to behave like it's static while other class members don't. The code... *all* class attributes are shared by all instances. however, instance attributes hide class attributes with the same name. in your case, you're hiding the

Re: Is a list static when it's a class member?

2006-10-10 Thread Ben Finney
glue [EMAIL PROTECTED] writes: I have a class with a list member and the list seems to behave like it's static while other class members don't. It's not static; rather, it's a class attribute, by virtue of being bound when the class is defined. Those are shared by all instances of the class.

Re: Is a list static when it's a class member?

2006-10-10 Thread Tom Plunket
Fredrik Lundh wrote: if you want separate instances to use separate objects, make sure you create new objects for each new instance. see Tim's reply for how to do that. kath's response is probably better. In Python, you don't define the instance members in the class scope like the OP has

Re: Is a list static when it's a class member?

2006-10-10 Thread Fredrik Lundh
Tom Plunket wrote: if you want separate instances to use separate objects, make sure you create new objects for each new instance. see Tim's reply for how to do that. kath's response is probably better. so what's the practical difference between def __init__(self, name):