How to optimise this code?

Hrvoje Niksic hniksic at xemacs.org
Tue Aug 21 15:56:18 EDT 2007


Christof Winter <winter at biotec.tu-dresden.de> writes:

> To get rid of the if statements, replace __init__ function with:
>
>      def __init__(self, tc):
>          functionToCall = eval("self.testCase%s" % tc)

Or functionToCall = getattr(self, "testCase" + tc)

eval can introduce unwanted side effects.



More information about the Python-list mailing list