[Beginner] Calling a function by its name in a string

Tito titogarcia_borra_esto at gmail.com
Wed Jul 27 14:46:16 EDT 2005


Thank you both for your quick answers.

What I wanted is to parameterize a function with another member 
function, like this:

def printFunctionForEach(collection, functionName):
   for elem in collection:
     print eval("elem." + functionName + "()")

Moreover, I wanted to do it with a property:

def printPropertyForEach(collection, propertyName):
   for elem in collection:
     print eval("elem." + propertyName)

Is there another approach to do it?

Regards,
Tito



More information about the Python-list mailing list