[Tutor] _init_ from manuals

Rick Pasotto rickp@telocity.com
Wed, 21 Aug 2002 18:30:48 -0400


On Wed, Aug 21, 2002 at 11:47:53PM +0200, Andrea Valle wrote:
> Dear all,
> I am starting with classes. Sorry, maybe something obvious.
> Reading the html manual I copied this example:
> 
> >>> class Complex:
> 	def _init_(self, realpart, imagpart):
> 		self.r=realpart
> 		self.i=imagpart
> 
> 
> >>> x=Complex(3.0,-4.5)
> 
> But I obtained:
> 
> Traceback (most recent call last):
>   File "<pyshell#5>", line 1, in ?
>     x=Complex(3.0,-4.5)
> TypeError: this constructor takes no arguments

The typography in books makes this difficult to see but there should be
*two* underscores before and after 'init' so that should be

def __init__(self, realpart, imagpart):

rather than

def _init_(self, realpart, imagpart):

-- 
"Be regular and orderly in your life, that you
may be violent and original in your work."
		-- Clive Barker
    Rick Pasotto    rickp@telocity.com    http://www.niof.net