look ate this line of code you made
[php]crit.talk('ralph') # like calling Critter.__init__().talk('ralph')[/php]
why is the __init__() method invoved. It seems to be using the Critter class and the talk method only.
edit added later//
I am looking at the link to the code snippet now :-)
The object crit is an alias of Critter(), which in turn is equivalent to Critter.__init__(). I shouldn't have used Critter.__init__().talk('ralph') the interpreter will balk at that construction. This just illustrates the sequence it calls.
To clear things up, whenever you invoke the class it will look at __init__() first, but only if it's there. You could have written the class Critter this way ...
[php]class Critter:
def talk(self,name):
print "I am born"
self.test = name
print self.test
print 'ya'
crit = Critter()
crit.talk('ralph')
[/php]
The method/function __init_() is only needed, if there are several other methods in the class that need common information.
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
Offline 5,792 posts
since Oct 2004