setattr函数在这个线程代码中做什么

2024-05-18 23:07:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习以下代码:

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在这里做什么,有人能解释一下吗?在

非常感谢


Tags: 代码selfinitdefconnectwrapperthreadclass
1条回答
网友
1楼 · 发布于 2024-05-18 23:07:42
setattr(object, name, value)

函数将值指定给所提供对象的属性。例如:setattr(objectA, 'attr', 'foo')相当于x.foobar = 'foo'。在

在您的代码中: setattr(self, "_thread", thread)相当于{}。在

有关详细信息,请访问python_setattr

我希望这对你有帮助!在

相关问题 更多 >

    热门问题