Re: [Zope3-Users] __init__ method never called?
Hi, On Mon, Sep 18, 2006 at 03:37:28PM +0100, John Smith wrote: Hi everyone! the class zope.app.publisher.browser.fileresource.FileResource inherits from BrowserView and Resource in that order. As far as I can work out, the __init__ method in Resource (zope.app.publisher.browser.resource.Resource) is never called. (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. If you want both base classes' init method to be called, do something like this: class MyView(BrowserView,Second): def __init__(self,context,request): BrowserView.__init__(self,context,request) Second.__init__(self,context,request) Regards, Frank ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] __init__ method never called?
Hi, On Tue, Sep 19, 2006 at 04:53:45AM -0400, Stephan Richter wrote: On Tuesday 19 September 2006 03:47, FB wrote: (Please correct me if I'm wrong, I'm not a Python guru :-) ) [snip] 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 Thank you for the clarification, Stephan. I know the meaning of 'super' a lot better now. Regards, Frank ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] __init__ method never called?
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 ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] __init__ method never called?
Hi, both Resource and BrowserView have a common parent class, viz Location, whose parent class is object. object | | Location / \ / \ / \ BrowserView Resource \/ \ / \/ FileResource As there are no calls to super() in any of the definitions of BrowserView, Reource, FileResource or Location, only the __init__ method of BrowserView would appear to be called because attribute lookup proceeds through the parent classes in the order they are provided in the definition. This can be practically tested by inserting a NotImplementedError into to the definition of Resource.__init__. I'm pretty certain that that method is never called, unless perhaps somewhere else in zope there is another class that inherits from it first. Cheers, John. --- Stephan Richter [EMAIL PROTECTED] wrote: 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 ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users ___ Yahoo! Photos NEW, now offering a quality print service from just 8p a photo http://uk.photos.yahoo.com ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] __init__ method never called?
Hi everyone! the class zope.app.publisher.browser.fileresource.FileResource inherits from BrowserView and Resource in that order. As far as I can work out, the __init__ method in Resource (zope.app.publisher.browser.resource.Resource) is never called. does anyone know if that Resource.__init__ method is used by anything else? Thanks, John ___ All new Yahoo! Mail The new Interface is stunning in its simplicity and ease of use. - PC Magazine http://uk.docs.yahoo.com/nowyoucan.html ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users