Class inheritance in python

classes in python inherit
now inherit

import pymongo
class MongodbPipeline(object):

    def __init__(self, mongodbHost, mongodbPort,mongodbName, mongondbCollection):
        self.mongodbHost = mongodbHost
        self.mongodbPort = mongodbPort
        self.mongodbName = mongodbName
        self.mongodbCollection = mongondbCollection

    def from_crawler(cls, crawler):
        return cls(mongodbHost=crawler.settings.get("MONGODB_HOST"), mongodbPort=crawler.settings.get("MONGODB_PORT"),
                   mongodbName=crawler.settings.get("XIAOMIQUAN_DBNAME"),
                   mongondbCollection=crawler.settings.get("XIAOMIQUAN_COLLECTION"))

    def open_spider(self, spider):
        self.client = pymongo.MongoClient(self.mongodbHost, self.mongodbPort)
        self.mongodb = self.Client[self.mongodbName]
        self.db = self.mongodb[self.mongondbCollection]

these three methods, except that the dbname and dbcollection of the database are different, and the others are all the same. Now how to inherit the three methods in the subclass

this is written in the initialization of the subclass

def __init__(self, mongodbHost, mongodbPort, mongodbName, mongondbCollection):
        super(XiaoMiQuanPipeline, self).__init__(mongodbHost, mongodbPort, mongodbName, mongondbCollection)
Sep.16,2021
Menu