我正在尝试弄清楚如何在Python threading.Thread
中将字符串作为参数传递。以前遇到过此问题:Python Threading String Arguments
有没有更好的传递字符串的方法?肯定有更明显的方法,而我对编程太陌生了,搞不懂。
代码块A
import threading
def start_my_thread():
my_thread = threading.Thread(target=my_func, args="string")
my_thread.start()
def my_func(input):
print(input)
结果:TypeError: my_func() takes 1 positional argument but 6 were given
代码块B
import threading
def start_my_thread():
my_thread = threading.Thread(target=my_func, args=("string",))
my_thread.start()
def my_func(input):
print(input)
结果:string
https://stackoverflow.com/questions/55368199
复制相似问题