newbie: constructor question

Alexander Eisenhuth stacom at stacom-software.de
Mon Oct 14 18:31:04 CEST 2002


Hallo everybody,

is it possible to implement multiple constructors with different no. of arguments for one class ?

  >>> class A:
	def __init__(self, a):
		self._a = a
	def __init__(self,a,b):
		self._b = b
	def __init__(self,a,b,c):
		self._c =c

  >>>obj = A(12)

Traceback (most recent call last):
    File "<pyshell#2>", line 1, in ?
      obj = A(12)
TypeError: __init__() takes exactly 4 arguments (2 given)
  >>>

--------------------------------
That doesn't work. Any suggestions ?

Thanks in forward

Alexander




More information about the Python-list mailing list