Lists in classes
the.mindstorm.mailinglist at gmail.com
Thu Jul 12 17:47:20 CEST 2007
On Jul 12, 6:23 pm, Jeremy Lynch <jeremy.ly... at gmail.com> wrote:
> Learning python from a c++ background. Very confused about this:
> class jeremy:
> def additem(self):
> temp = jeremy()
> print temp.list
> temp2 = jeremy()
> print temp2.list
> The output gives:
> 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.
You are defining the list in the class context and so it becomes a
For defining instance members you need to always prefix those with
self (this) in the
contexts it is available (f.e. in the instance method context).
.w( the_mindstorm )p.
More information about the Python-list