[Tutor] Classes
Michael Janssen
Janssen@rz.uni-frankfurt.de
Tue Feb 25 16:18:03 2003
On Tue, 25 Feb 2003, Kenneth Boehme wrote:
> class Circle:
> def _init_(self, rad=5):
> self.radius=rad
>
[...]
> >>> y=Circle(10)
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> TypeError: this constructor takes no arguments
> >>>
>
> What I'm doing wrong?
two underscores: __init__(self, rad=5) . Now Python knows what to do with
this __init__() (and take it as the constructor). In your case _init_() is
a normal method and y hasn't a __init__() operator.
Michael
>
> Thanks,
>
> Kenneth