Overriding methods in classes you don't control
Steven Bethard
steven.bethard at gmail.com
Mon Mar 28 00:24:03 EST 2005
Alex VanderWoude wrote:
> Basically I want to change wxFrame.__init__ so that it looks sort of like
> this:
>
> def __init__(self, *args, **kwargs):
> # Some enhancements here.
> # The original code of this method, including the call to its
> ancestor.
> # Some more enhancements here.
>
> And then I can replace wxFrame's __init__ with my new version by assigning
> it before any frames are instantiated.
Maybe you can do something like:
oldinit = wxFrame.__init__
def newinit(self, *args, **kwargs):
# Some enhancements here.
oldinit(self, *args, **kwargs)
# Some more enhancements here.
wxFrame.__init__ = newinit
that is, save the old __init__ method so that it can be accessed from
within your new __init__ method.
STeVe
More information about the Python-list
mailing list