bend or redirect a class method and then call it again

Jeff Shannon jeff at ccvcorp.com
Thu Jul 22 19:58:33 CEST 2004


Franz Steinhaeusler wrote:

>#drFrame is inherited from wx.Frame
>#in drFrame there are some calls to SetStatusText
>
>import wx
>from drpython import DrFrame
>
>def Plugin(DrFrame):
>
>  def SetStatusText(text, col):
>    #[...]
>
>  def NewStatusText(text, col=0):
>    SetStatusText(text, col)
>
>  setattr(DrFrame, 'SetStatusText', NewStatusText)
>  
>


What's the point of this extra 'NewStatusText' method?  You're already 
overriding SetStatusText.  Without the NewStatusText and the setattr() 
call, when someone calls SomePluginObject.SetStatusText(), it will call 
your new version rather than the wx.Frame (or DrFrame) version -- that's 
the whole point of inheritance.  (This is true even when the 'someone' 
is the object itself, from within the DrFrame base class.  The *only* 
way to get the base class version(s) is by explicitly asking for it.)  
The extra method and setattr() don't seem to be gaining you anything. 

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list