Common list in distinct objects'

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue Jul 16 04:26:08 EDT 2002


otijim at yahoo.com (Jake R) wrote in news:3d332491.362646438 at news.byu.edu:

> Now that I think about it some more I seem to remember reading
> somewhere in the tutorial that class definition is only processed once
> and being so means that the default list (myList=[]) in my __init__ is
> only created once and thus any objects created all point to the same
> list unless I create a new list (ie pass one in or have the __init__
> function do it when its called)
> 
> Does that sound right?  Still....I don't think thats what way it ought
> to behave.

Please read the FAQ entry number 6.25:
 http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.025.htp

It is all extremely logical once you understand what is going on, but 
admittedly can be confusing for beginners.

You might also find it useful to read the eff-bot guide to Python objects 
at http://effbot.org/guides/python-objects.htm to make sure you understand 
how Python's objects and assignments work. Also the tutorial section 4.7.1 
has the 'important warning' that you half remembered.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list