[Tutor] _init_ from manuals

Andrea Valle marta_andrea@libero.it
Wed, 21 Aug 2002 23:47:53 +0200


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


A similar behaviour (at least, to me) happens with the following example
form a Python book. I copied:
>>> class Vector:
	def _init_(self,a,b):
		self.a=a
		self.b=b
	def stampa(self):
		print self.a, self.b


>>> v1=Vector(2,10)

But obtained:

Traceback (most recent call last):
  File "<pyshell#16>", line 1, in ?
    v1=Vector(2,10)
TypeError: this constructor takes no arguments

Any help is much appreciated.
Thanks as usual

-a-