我是很新,Python和正在研究通過這篇文章使用線程的一些代碼: Python - Using threads or a queue to iterate over a for loop that calls a function線程和傳遞價值觀與** kwargs錯誤類型錯誤
我想知道爲什麼這個簡單的例子代碼中的錯誤出到
Error: line 1: TypeError: file <maya console> line 4: __init__() got
an unexpected keyword argument 'A' #
我的代碼:
import threading
class Test(threading.Thread):
def __init__(self, **kwargs):
super(Test, self).__init__(**kwargs)
self.__dict__.update(**kwargs)
A = None
B = 1
test = Test(A = A, B = B)
print test.A
print test.B
我的假設是它具有與super(Test, self).__init__(**kwargs)
調用來完成,但我不知道如何解決它。我的目標是傳遞相當多的論據,這就是爲什麼我開始使用**kwargs
。
好吧,假設我想使用** kwargs來接受輸入,那麼將如何完成? – Jetbo 2013-02-25 13:08:28
好吧,這會有很大的幫助!如果有大量屬性傳遞,仍然使用'self .__ dict __。update(** kwargs))'來保持優雅? – Jetbo 2013-02-25 13:16:55
你先生是個天才。非常感謝你。 – Jetbo 2013-02-25 13:21:13