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
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
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):
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
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)
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)
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
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.
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
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):
10 matches
Mail list logo