我有一個Python線程的問題,並在參數中發送一個字符串。Python線程字符串參數
def processLine(line) :
print "hello";
return;
。
dRecieved = connFile.readline();
processThread = threading.Thread(target=processLine, args=(dRecieved));
processThread.start();
其中dRecieved是由連接讀取的一行的字符串。它稱爲一個簡單的功能,它現在只有一個打印「你好」的工作。
不過,我得到以下錯誤
Traceback (most recent call last):
File "C:\Python25\lib\threading.py", line 486, in __bootstrap_inner
self.run()
File "C:\Python25\lib\threading.py", line 446, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: processLine() takes exactly 1 arguments (232 given)
232是我試圖通過字符串的長度,所以我想它分解成每個字符,並試圖通過這樣的論點。它正常工作,如果我只是正常調用該函數,但我真的想把它設置爲一個單獨的線程。
爲什麼每行末尾都有分號? – Maikflow 2015-09-21 02:55:00