need for help

Alister alister.ware at ntlworld.com
Fri Mar 1 17:01:56 EST 2013


On Fri, 01 Mar 2013 19:35:14 +0100, leonardo selmi wrote:

> hi guys
> 
> i typed the following program:
> 
> class ball:
>     def _init_(self, color, size, direction):
>         self.color = color self.size = size self.direction = direction
> 
>     def _str_(self):
>         msg = 'hi, i am a ' + self.size + ' ' + self.color + 'ball!'
>         return msg
> 
> myball = ball('red', 'small', 'down')
> print my ball
> 
> BUT I GOT THIS ERROR:
> 
> Traceback (most recent call last):
>   File "/Users/leonardo/Documents/ball2.py", line 11, in <module>
>     myball = ball('red', 'small', 'down')
> TypeError: this constructor takes no arguments
> 
> can you kindly tell me what is wrong?
> thanks a lot!

as far as I can see is_init_ should be __init__ (double underscore)



-- 
The autodecrement is not magical.
             -- Larry Wall in the perl man page



More information about the Python-list mailing list