[Tutor] Bound To Be A Typo Thank You

earlylight publishing earlylightpublishing at yahoo.com
Mon Dec 17 21:42:31 CET 2007


I have no idea why I did that either.  I know perfectly well it's supposed to be 2 underscores!  Thanks to everyone who spotted the problem.  

"Michael H. Goldwasser" <goldwamh at slu.edu> wrote:  
You've inadvertently used three underscores around __init__ rather
than two, and therefore you are not really defining __init__ but
instead are relying upon the inherited one from object (which takes no
parameters).

With regard,
Michael

On Monday December 17, 2007, earlylight publishing wrote: 

> 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 
> crit1 = Critter("Poochie")
> TypeError: default __new__ takes no parameters



       
---------------------------------
Never miss a thing.   Make Yahoo your homepage.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071217/923166bf/attachment-0001.htm 


More information about the Tutor mailing list