Python abstract class, abstract method implementation, python Abstract
Because python does not have abstract classes or interfaces, You need to implement the abc. py class library using the following methods:
From abc import ABCMeta, abstractmethod # Abstract class Headers (object): _ metaclass _ = ABCMeta def _ init _ (self): self. headers = ''@ abstractmethod def _ getBaiduHeaders (self): pass def _ str _ (self): return str (self. headers) def _ repr _ (self): return repr (self. headers) # implementation class BaiduHeaders (Headers): def _ init _ (self, url, username, password): self. url = url self. headers = self. _ getBaiduHeaders (username, password) def _ getBaiduHeaders (self, username, password): client = GLOBAL_SUDS_CLIENT.Client (self. url) headers = client. factory. create ('ns0: authheader') headers. username = username headers. password = password headers. token = _ baidu_headers ['Token'] return headers
If the subclass does not implement the _ getBaiduHeaders method of the parent class, a TypeError: Can't instantiate abstract class BaiduHeaders with abstract methods exception is thrown.