Backward chaining for __init__?

Bernhard Herzog herzog at
Wed May 3 14:44:05 CEST 2000

nickm at (Nick Mathewson) writes:

>   3) What if we want to initialize some of the object's state before we 
>      call the ctor? (This is unusual, but not IMO completely pathological.)

It's even hard to avoid in some situations:

class Base:

	def __init__(self):

	def do_something(self):

class Derived(Base):

	def __init__(self):
		self.var = 0

	def do_something(self):
		print self.var

Unlike in C++, the self.do_something() in Base.__init__ will call
Derived.do_something, so you have to initialize self.var before calling
the base class constructor.

Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at  |

More information about the Python-list mailing list