In python I can do this:
import mechanize
class MC (object):
def __init__(self):
self.Browser = mechanize.Browser()
self.Browser.set_handle_equiv(True)
def open (self,url):
self.url = url
self.Browser.open(self.url)
My question is: how can I __init__ a parent class method in a subclass (that is something like this):
class MC (mechanize.Browser):
def __init__(self):
self.Browser.set_handle_equiv(True)
Help much appriciated!
Just call the method directly, methods on base classes are available on your instance during initialisation:
You probably want to call the base-class
__init__method as well though:We need to call the
__init__directly becauseBrowseris an old-style python class; in a new-style python class we’d usesuper(MC, self).__init__()instead, where thesuper()function provides a proxy object that searches the base class hierarchy to find the next matching method you want to call.