shanenin Posted July 2, 2005 Report Share Posted July 2, 2005 I am slowly absorbing these python class concepts(kinda)this fails with an errorclass Critter(object): def __init__(self): print "I am born" def talk(self,name): self.test = name print self.testcrit = Critter('ralph')crit.talk()this one worksclass Critter(object): def __init__(self,name): print "I am born" self.test = name print self.test def talk(self): print 'ya' crit = Critter('ralph')crit.talk()this seems that the parameter 'ralph' can only be passed to the __init__ method, but not the talk method. Is that a correct assumption, if so why? Quote Link to post Share on other sites
gvim Posted July 2, 2005 Report Share Posted July 2, 2005 ....this fails with an errorclass Critter(object): def __init__(self): print "I am born" def talk(self,name): self.test = name print self.testcrit = Critter('ralph')crit.talk()this one worksclass Critter(object): def __init__(self,name): print "I am born" self.test = name print self.test def talk(self): print 'ya'crit = Critter('ralph')crit.talk()this seems that the parameter 'ralph' can only be passed to the __init__ method, but not the talk method. Is that a correct assumption, if so why?<{POST_SNAPBACK}>The first piece of code works, just put your 'ralph' where your talk is.... like soclass Critter(object): def __init__(self): print "I am born" def talk(self,name): self.test = name print self.testcrit = Critter()crit.talk('ralph') Quote Link to post Share on other sites
shanenin Posted July 2, 2005 Author Report Share Posted July 2, 2005 (edited) Thanks :-)it seems that any parameters given directly to the object are passed only to the __init__ constructor(for the most part)@jclyou kind of already answered this for me before, but I was still not sure Edited July 2, 2005 by shanenin Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.