[Zope3-Users] __init__ method never called?

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Sep 19 05:47:30 EDT 2006


On Tuesday 19 September 2006 03:47, FB wrote:
> (Please correct me if I'm wrong, I'm not a Python guru :-) )
>
> Whenever you inherit from two classes, only the first class'
> __init__ method is called implicitely on create of a new instance.

>>> class First(object):
...     def __init__(self):
...         print 'init 1-before'
...         super(First, self).__init__()
...         print 'init 1-after'
...
>>> class Second(object):
...     def __init__(self):
...         print 'init 2-before'
...         super(Second, self).__init__()
...         print 'init 2-after'
...
>>> class Join(First, Second):
...     def __init__(self):
...         print 'init 3-before'
...         super(Join, self).__init__()
...         print 'init 3-after'
...
>>> Join()
init 3-before
init 1-before
init 2-before
init 2-after
init 1-after
init 3-after
<__main__.Join object at 0xb7b5fb6c>
>>>

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training


More information about the Zope3-users mailing list