Barraka
Barraka

Reputation: 52

Passing multiple functions with arguments to a main function

I want to execute a number of functions, in another function.

I'm trying to achieve something like this:

def first(thisString,thisNumber):
    print(thisString,thisNumber)

def second(a,b,c):
    print(a+b+c)

def runningOne(*args):
    for x in args:
        x[0](x[1])

one=[first,("try",15)]
two=[second,(4,3)]
runningOne(one,two)

But I don't know how to pass the arguments in the "runningOne" function.

Thanks,

Upvotes: 0

Views: 549

Answers (2)

Jonathan1609
Jonathan1609

Reputation: 1919

you forgot to put an asterisk,

def first(thisString,thisNumber):
    print(thisString,thisNumber)

def second(a,b,c):
    print(a+b+c)

def runningOne(*args):
    for x in args:
        x[0](*x[1])

one=[first,("try",15)]
two=[second,(4,3, 8)]
runningOne(one,two)

That's the fixed code, you had to put an asterisk before the x[1] and you also forgot to specify the third number in two.

Upvotes: 3

Guy
Guy

Reputation: 50819

Use * to extract the parameters values

def runningOne(*args):
    for x in args:
        x[0](*x[1])

Upvotes: 2

Related Questions