Python教程

Python多继承时初始化父类的属性

本文主要是介绍Python多继承时初始化父类的属性,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
class SSHClient():
    def __init__(self,host=None,port=22,username=None,password=None):
        self.host = host
        self.port = port
        self.username = username
        self.password = password

    def exect(self, cmd):
        # 创建ssh对象
        ssh = paramiko.SSHClient()
        # 允许连接不在know_hosts文件中的文件
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(self.host,self.port,self.username,self.password)
        sin, sout, sstr = ssh.exec_command(cmd)
        ret = sout.read()
        return ret

class Tags(APIView,SSHClient):

    def __init__(self):

        self._response = ReturnResponse()

        SSHClient.__init__(self,host=h1['host'],port=h1['port'],username=h1['username'],password=h1['password'])

单继承时初始化父类属性:

super(xxx,self)._ _init _ _(*args)

多继承时

要通过每个父类._ _ init _ _(*args)来初始化父类的属性

这篇关于Python多继承时初始化父类的属性的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!