Common list in distinct objects'
Jake R
otijim at yahoo.com
Tue Jul 16 10:14:48 EDT 2002
I knew I had read that 'Important Warning' somewhere. I only
remembered about 5 minutes after my posting.
It describes a short snippet to "overcome" this by using None and an
IF...ELSE clause.
I just wonder what is the preferred result. IMO each call should
return a new and distinct list (to me this makes sense since in my
case each call creates a new and distinct object. But other than PHP
I have never used a language that allows default parameter values so
maybe this is an already established standard that I'm not familiar
with.
On Tue, 16 Jul 2002 08:26:08 +0000 (UTC), Duncan Booth
<duncan at NOSPAMrcp.co.uk> wrote:
>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