[Tutor] Bound To Be A Typo

Alan Gauld alan.gauld at btinternet.com
Mon Dec 17 21:33:07 CET 2007


Your init method has 3 underscores each side, it should be 2.
(As all the magic methods in Python do)

The result is the init is not recognised as an initialiser and
the default object.new method is called. as the messaage
says it takes no parameters...

HTH,

Alan G.

"earlylight publishing" <earlylightpublishing at yahoo.com> wrote in 
message news:208320.1227.qm at web45101.mail.sp1.yahoo.com...
> Okay I copied this code directly from a book (author Michael Dawson) 
> and it's not working.  I'm sure I've missed something obvious like 
> the spacing or something but I've been staring at it for 10 minutes 
> and I can't see it.  I'll put the code and error message below.  Can 
> someone else spot the problem?
>
>  class Critter(object):
>    """A virtual pet"""
>    def ___init___(self, name):
>        print "A new critter has been born!"
>        self.name = name
>
>    def __str__(self):
>        rep = "Critter object\n"
>        rep += "name: " + self.name + "\n"
>        return rep
>
>    def talk(self):
>        print "Hi, I'm", self.name, "\n"
>  #main
> crit1 = Critter("Poochie")
> crit1.talk()
>
>  Here's the error message:
>
>  Traceback (most recent call last):
>  File "C:/Python25/attributecrit.py", line 15, in <module>
>    crit1 = Critter("Poochie")
> TypeError: default __new__ takes no parameters
>
>
>
> ---------------------------------
> Looking for last minute shopping deals?  Find them fast with Yahoo! 
> Search.


--------------------------------------------------------------------------------


> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list