Isabel Cariod Isabel Cariod - 1 year ago 49
Python Question

Python give number of args to an imported function

I'm trying to give an argument to an imported function.

I have

import sc1 #import
from threading import Thread


And a function in

def main(name):
print "Hello ",name


TypeError: main() takes exactly 1 argument (4 given)

If I give just one
then it works fine,

does anyone have any idea what I can do?

Answer Source

You want to pass a tuple of args:


In your case, since str are iterable, the Thread is trying to unpack "J" "o", "h", "n" as the arguments rather than passing the entire thing as an atomic unit.