On Feb 11, 9:15 am, DataSmash <r...@new.rr.com> wrote: > Can someone help me understand why Example #1 & Example #2 will run > the functions, > while Example #3 DOES NOT? > Thanks for your time! > R.D. > > def One(): > print "running fuction 1" > def Two(): > print "running fuction 2" > def Three(): > print "running fuction 3" > > # Example #1 > fList = ["Two()","Three()"] > for func in fList: > exec func > > # Example #2 > Two() > Three() > > # Example #2 > fList = ["Two()","Three()"] > for func in fList: > func
Example 1 is executing the code inside strings Example 2 is evaluating two functions and throwing the result away Example 3 is evaluating literals and throwing the result away I don't know why you would expect the third example to run the functions. Maybe running this version will enlighten you: fList = ["random","stuff"] for func in fList: func -- http://mail.python.org/mailman/listinfo/python-list