首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >将字符串作为参数传递到Python的threading.Thread中

将字符串作为参数传递到Python的threading.Thread中
EN

Stack Overflow用户
提问于 2019-03-27 08:48:43
回答 1查看 83关注 0票数 0

我正在尝试弄清楚如何在Python threading.Thread中将字符串作为参数传递。以前遇到过此问题:Python Threading String Arguments

有没有更好的传递字符串的方法?肯定有更明显的方法,而我对编程太陌生了,搞不懂。

代码块A

代码语言:javascript
复制
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

代码语言:javascript
复制
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

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55368199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档