[Tutor] building callable function names on the fly
Mallett, Roger
rmallett@rational.com
Mon, 18 Dec 2000 14:03:30 -0800
I would like to know if function names can be build on the fly and then the
newly built function named called.
For example:
L1: for marker in MARKER_LIST:
L2: if index_for_marker = my_htm_string.find(marker) > -1:
L3: func_name = 'Process_' + Marker
L4: my_processed_htm_string = func_name(my_htm_string)
L5: def Process_1():...
L6: def Process_2().... etc.
L3/L4 is the question here. It is obviously incorrect, but I would like to
know what the correct way would be. I could use a bunch of *elif*
statements (one for each element in MARKER_LIST), but I would like to build
the name of the function to be called so that I have less lines to manage.
In other words, if marker = '1', then I'd like to call Process_1, however,
if marker = '2' then I'd like to call Process_2.
Can such be done?
Roger Mallett