Reputation: 149
Suppose i have a list:
a=['hello.com','ok.com']
i have two function:
def f0(id):
try:
model.objects.get(links=id)
except:
model(modelfield=id).save()
def f1(request):
for i in a:
t1=thread.Thread(target=f0,args=(i))
t1.start()
While i try to run this on my server , its giving me error .
TypeError: f0() takes 1 positional argument but 9 were given
Kindly tell me whats the problem .
Upvotes: 3
Views: 3646
Reputation: 76
In 'args=(i)', (i) is not a tuple. Convert (i) into a tuple by appending , so the right statement will be: t1=thread.Thread(target=f0,args=(i,))
Upvotes: 0
Reputation: 1123930
You are passing in a single string as the args
value:
args=(i)
That's not a tuple, that's a grouped expression containing just 'hello.com'
, an iterable with 9 separate elements (single-character strings).
Add a comma; tuples are formed by the comma, not the parentheses (although you need parentheses to disambiguate the tuple from other arguments in a call):
args=(i,)
or if you find that confusing, use a list:
args=[i]
Upvotes: 8