【发布时间】:2017-10-04 14:15:56
【问题描述】:
我正在学习一段代码如下:
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文档吗? -
是的,我明白了,但我不明白我们为什么要设置这样的属性。
-
我们不可能知道为什么你的代码设置了这个属性。我们对
TestApp类或TestWrapper类或TestClient类一无所知。所以我最好的猜测是:你设置属性是因为你想稍后访问它。
标签: python multithreading