OOP / language design question
Duncan Booth
duncan.booth at invalid.invalid
Tue Apr 25 09:25:31 EDT 2006
Carl Banks wrote:
> You know, Python's __init__ has almost the same semantics as C++
> constructors (they both initialize something that's already been
> allocated in memory, and neither can return a substitute object).
There is a significant difference: imagine B is a base type and C a
subclass of B:
When you create an object of type C in Python, while B.__init__ is
executing self is an object of type C (albeit without all the attributes
you expect on your C).
In C++ when the B() constructor is executing the object is an object of
type B. It doesn't become a C object until the C() constructor is
executing.
In other words, the object is constructed in Python before any __init__ is
called, but in C++ it isn't constructed until after all the base class
constructors have returned.
More information about the Python-list
mailing list