python - 将可变长度列表作为参数传递给线程函数

标签 python list parameter-passing python-multithreading

我正在尝试将列表作为参数传递给线程函数。这个列表的长度可能会有所不同,但我不知道该怎么做。下面是我正在使用的代码。现在,我只想能够将列表放入线程函数中并将其打印在屏幕上。

#!/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/

相关文章:

python - 使用正则表达式从电子邮件中捕获日期

Python:捕获 QListWidget 中的重新排序事件?

c++ - 如何省略 C++ 中不同参数的复制函数定义

c# - 使用参数化查询填充数据列表

python - TypeError:无法创建一致的方法解析顺序(MRO)

javascript - 在 django 中提交表单上的两个返回语句

c++ - 适用于 begin() 但不适用于 rbegin() 的映射迭代器

c# - 使用 LINQ 将 List<U> 转换为 List<T>

python - 基于纬度/经度的点列表之间的距离

C++11:参数包扩展计数器