繁体   English   中英

初始化线程时如何将 arguments 传递给 class?

[英]how to pass arguments to a class when initializing a thread?

我试图调用等于表中行数的类数并在那里传递参数。 但我得到一个错误

NameError: name 'iterr' is not defined. Did you mean: 'iter'?

class App(iterr):
   def __init__(self):


if __name__ == '__main__':
table = open('config/url.txt', encoding = 'utf-8')
table_url = ''
for u in table:
    table_url = u
gc = gspread.service_account(filename='config/auth.json')
sh = gc.open_by_url(table_url)
worksheet = sh.get_worksheet(0)
values_list = worksheet.col_values(1)
threads = len(values_list)
i = 1
while i < threads+1:
    thread = threading.Thread(target=App, args=(i,))
    thread.start()

你在初始化 function 上传递你的 arguments。

class App():
   def __init__(self, iterr):

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM