1
我學習一段代碼如下:什麼SETATTR功能做這個線程代碼
class TestApp(TestWrapper, TestClient):
def __init__(self, ipaddress, portid, clientid):
TestWrapper.__init__(self)
TestClient.__init__(self, wrapper=self)
self.connect(ipaddress, portid, clientid)
thread = Thread(target = self.run)
thread.start()
setattr(self, "_thread", thread)
self.init_error()
我很感興趣,它的線程組件,我不明白是什麼SETATTR在這裏所做的,可有人請解釋?
非常感謝
它相當於'self._thread = thread'。你讀過'setattr'文檔嗎? –
[在python中使用setattr()]的可能的重複(https://stackoverflow.com/questions/9561174/using-setattr-in-python) –
是的,我明白了,但我不明白爲什麼我們設置了一個屬性像那樣。 – Liam