[Tutor] wrap methods for logging purposes

Evert Rol evert.rol at gmail.com
Thu Oct 7 14:10:37 CEST 2010


> I used a the recipe (http://aspn.activestate.com/ASPN/Coo.../Recipe/198078)  used to wrap methods for logging purposes. logging classes. But it does seem to work well with classes inherit form other classes -  i get recursion errors!
> 
> Here is an example of the classes .. 
> 
> class Base(MetaClass):
> 
> class BFrame(BaseFrame):
>     def __init__(self, pathname=''):
>         Base.__init__(self, pathname = pathname)
> 
> When i instatiate BiasFrame()

Sorry, but I can't see how this code example above can work;
- there is no definition of class Base. There's not even 'pass' statement!
- Where is MetaClass's definition?
- you instantiate BiasFrame, but that's not defined.
- BFrame inherits from BaseFrame, which I don't see defined inherit.
- I definitely would advise against calling Base.__init__ if you inherit BFrame from BaseFrame: BaseFrame.__init__ makes more sense.
  But rather, use super instead. In Python 2:
    super(Base, self).__init__(pathname=pathname)


  Evert


> 
> below is the  OUTPUT
> 
> logmethod <BFrame object at 0x9c32d90> __init__ () {}
> logmethod <BFrame object at 0x9c32d90> __init__ () {'pathname': ''}
> logmethod <BFrame object at 0x9c32d90> __init__ () {'pathname': ''}
> logmethod <BFrame object at 0x9c32d90> __init__ () {'pathname': ''}
> logmethod <BFrame object at 0x9c32d90> __init__ () {'pathname': ''}
> .
> .
> RuntimeError: maximum recursion depth exceeded in cmp
> 
> It starts with the __init__ of BFrame, that's correct. In the __init__ of BFrame is a call to Base.__init__ with the pathname as argument. That is the second call to __init__ in the output, but the class is wrong ! Instead of the __init__ of Base the __init__ of BFrame is called.
> 
> is there any way i can correct this?
> 
> -- 
> += Johnson
> -------------------------------------- _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list