我正在尝试将列表作为参数传递给线程函数。这个列表的长度可能会有所不同,但我不知道该怎么做。下面是我正在使用的代码。现在,我只想能够将列表放入线程函数中并将其打印在屏幕上。
#!/usr/bin/python
import threading
import Queue as queue
def generateRange(starting_chars=(*args)):
print str(starting_chars)
for i in range(32,126):
q = queue.Queue()
theArgs = [i,32,32]
threads = [ threading.Thread(target=generateRange,args=theArgs) ]
# generateRange([i,32,32])
for th in threads:
th.daemon = True
th.start()
我收到此错误:
File "./test.py", line 6
def generateRange(starting_chars=(*args)):
^
SyntaxError: invalid syntax
我做错了什么?
最佳答案
您可以将语法更改为此,否则args
将不会被定义:
def generateRange(*starting_chars):
print str(starting_chars)
关于python - 将可变长度列表作为参数传递给线程函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47235791/