functions which take functions
Kiuhnm
kiuhnm03.4t.yahoo.it
Thu Apr 12 11:58:43 EDT 2012
On 4/12/2012 8:07, Tim Roberts wrote:
> Kiuhnm<kiuhnm03.4t.yahoo.it> wrote:
>>>> That won't do. A good example is when you pass a function to re.sub, for
>> instance.
>> This is an odd request.
All shall be revealed :)
>> I often pass functions to functions in order to simulate a C switch
> statement, such as in a language translator:
>> commands = {
> 'add': doAdd,
> 'subtract' : doSubtract,
> 'multiply' : doMultiply,
> 'divide' : doDivide
> }
>> nextCommand = parseCommandLine( line )
> invokeCommand( commands[NextCommand] )
I like that very much. Thank you.
Kiuhnm
More information about the Python-list
mailing list