you can also create a dict with the classes themselves as keys, not necessarily with class names
typefunc={ int:lambda x: x*2, str:lambda s:'(*(%s)*)'%s } def transform (param): print typefunc[type(param)](param) transform (1) >>> 2 transform ("hi") >>> (*(hi)*)
here typefunc is a dict that displays a function for each type. transform gets this function and applies it to the parameter.
Of course, it would be much better to use the "real" OOP
Javier Feb 06 '09 at 19:15 2009-02-06 19:15
source share