How to optimise this code?

Wayne Brehaut wbrehaut at mcsnet.ca
Tue Aug 21 16:56:31 EDT 2007


On Tue, 21 Aug 2007 21:56:18 +0200, Hrvoje Niksic <hniksic at xemacs.org>
wrote:

>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.

Hence the slogan "Do No Eval!"

wwwayne



More information about the Python-list mailing list