A TYPICAL NEWBIE MISTAKE?

Courageous jkraska1 at san.rr.com
Sun May 14 23:06:08 EDT 2000


> The `i', `f', etc.  within the `__init__' definition are strictly local
> to `__init__', and do not exist once the routine has been executed.
> Use `self.i', etc. within `__init__' (say), if you want variables that
> are local to each particular instance.

Yeah, actually I knew all that, but I sure did mangle what
I was trying to say, didn't I? Good point about running code
through the interpreter before posting, particularly when you're
a newbie who's fingers have a prediliction for other languages. :)-

My key point was that it's easy to get confused when assignment
to self.attribute overrides the common class attribute. To wit:

>>> 
>>> class Base:
	ll=[]
	
	
>>> b1 = Base()
>>> b1.ll
[]
>>> be = Base()
>>> b2.ll
[1]
>>> b1.ll.append(1)
>>> b1.ll
[1]
>>> b2.ll
[1]
>>> 

For some reason, because of my previous experiences with
assignment, I assumed append would have the same semantic.
Not so. I understand why not so, but I think it's interesting
anyway...



C/



More information about the Python-list mailing list