[Tutor] [LONG] help on self

alan.gauld@bt.com alan.gauld@bt.com
Wed, 14 Apr 1999 09:53:36 +0100


> one of my biggest problems in object oriented python is 'self' ...
> 
> As far as I know it's a referecne to the calling object.

No, it refers to the *called* object.
Thus in your case there is no self.string attribute in
either parser nor iteration classes. You actually want 
to somehow get the token to print its string prior to 
calling parseHeader.

The whole point of OOP is that objects know nothing about 
who is calling them. Thats what gives the independance 
that allows objects to be reused in ither applications. 

You can of course explicitly pass the token in as an 
object this parseHeader starts like:

def parseHeader(self,	# the parser
		    tok)    # the token calling the parser
	print tok.string  # better if token had a print method tho'...
....


Does that help?

Alan G.