Backward chaining for __init__?
Bernhard Herzog
herzog at online.de
Wed May 3 08:44:05 EDT 2000
nickm at mit.edu (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):
self.do_someting()
def do_something(self):
pass
class Derived(Base):
def __init__(self):
self.var = 0
Base.__init__(self)
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 online.de | http://sketch.sourceforge.net/
More information about the Python-list
mailing list