Lists in classes

2007-07-12 Thread Jeremy Lynch
Hello,

Learning python from a c++ background. Very confused about this:


class jeremy:
list=[]
def additem(self):
self.list.append("hi")
return

temp = jeremy()
temp.additem()
temp.additem()
print temp.list

temp2 = jeremy()
print temp2.list
==
The output gives:
['hi','hi']
['hi','hi']

Why does adding items to one instance produce items in a separate
instance? Doesn't each instance of jeremy have its' own "list"?

Many thanks for clearing up this newbie confusion.

Jeremy.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lists in classes

2007-07-12 Thread Jeremy Lynch
Thanks for all the replies, very impressive. Got it now.

Jeremy.



On Jul 12, 4:23 pm, Jeremy  Lynch <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Learning python from a c++ background. Very confused about this:
>
> 
> class jeremy:
> list=[]
> def additem(self):
> self.list.append("hi")
> return
>
> temp = jeremy()
> temp.additem()
> temp.additem()
> print temp.list


>
> temp2 = jeremy()
> print temp2.list
> ==
> The output gives:
> ['hi','hi']
> ['hi','hi']
>
> Why does adding items to one instance produce items in a separate
> instance? Doesn't each instance of jeremy have its' own "list"?
>
> Many thanks for clearing up this newbie confusion.
>
> Jeremy.


-- 
http://mail.python.org/mailman/listinfo/python-list