簡體   English   中英

為具有多個超類的類調用超類函數

[英]Calling a superclass function for a class with multiple superclass

我有一個擴展兩個類的類,其中一個包括threading.Thread。 如何從子類調用threading.Thread的start方法?

class Poller(threading.Thread, <some other class>):
    """
    poller code 
    """
    def start():
        return super(Poller,self).start() 

我想啟動線程類的啟動功能。 這行不通嗎?

如果您想確保僅調用Thread的啟動,可以執行以下操作:

def start(self):
    threading.Thread.start(self)

請注意,這將避免其他基類的start方法,並且可能不是您想要的

start()方法缺少“自我”關鍵字

class Poller(threading.Thread, <some other class>):
    """
    poller code 
    """
    def start(self):
        return super(Poller,self).start() 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM