Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do this in Python? List to function

Tags:

python

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.

like image 595
TIMEX Avatar asked May 24 '26 15:05

TIMEX


1 Answers

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.

like image 62
Jonathan Feinberg Avatar answered May 26 '26 06:05

Jonathan Feinberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!