TIMEX
TIMEX

Reputation: 271714

How do I do this in Python? List to function

def getStuff(x):
    return 'stuff'+x

def getData(x):
    return 'data'+x


thefunctions = []
thefunctions.append("getStuff")
thefunctions.append("getData")

for i in thefunctions:
   print i('abc')

Is this possible? Thank you.

Upvotes: 2

Views: 163

Answers (1)

Jonathan Feinberg
Jonathan Feinberg

Reputation: 45324

thefunctions = [ getStuff, getData ]
for f in thefunctions:
    print f('shazam')

Once you've done a def statement, you've associated a name with a function. Just use that name to refer to the function.

Upvotes: 12

Related Questions