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)来初始化父类的属性


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM