【发布时间】:2018-01-28 12:03:46
【问题描述】:
class myThread(threading.Thread):
def __init__(self,str1,str2):
threading.Thread.__init__(self)
self.str1 = str1
self.str2 = str2
def run(self):
run1(self.str1,self.str2)
我知道 __init__ 是用来初始化一个类的,但是下一行它的用途是什么。有什么替代方法吗?
【问题讨论】:
-
第二个init方法用于调用超类的init方法进行初始化。
-
看我的回答@Talmoor
-
你完全不需要创建
myThread子类,你可以直接使用Thread类,例如:mythread = threading.Thread(target=run1, args=('a', 'b'))mythread.start()。另见stackoverflow.com/questions/20736131/…
标签: python