Mick Krippendorf mad.mick at gmx.de
Sun Oct 11 21:10:55 CEST 2009

TerryP schrieb:
> Note: let Commands be a dictionary, such that { "ham" : ...,
> "spam" : ..., "eggs" : ... }.
>   args = re.split('\s', line)
>   cmd  = args.pop(0)
>   if cmd in Commands:
>       Commands[cmd](args)
>   else:
>       raise SyntaxWarning("Syntax error in above program")
> [...] I might take flak here, for writing something like 'dict[key]
> (func_args)' instead of something more Pythonic, but the code serves
> to express a point, not teach a system of branch of Zen :-P.

But this *is* pythonic. It must be, since Guido has identified it as a
Pattern and named it the Dommand Dispatch Pattern. Also, it is in
perfect compliance to The Zen (import this).


More information about the Python-list mailing list