|
|
|
|
|
by bjourne
2181 days ago
|
|
Suppose you are dispatching on token types. You could write something like this: handlers = {'start' : handle_start, 'jump' : handle_jump, 'end' : handle_end, ...}
for tok, arg in tokens:
if tok not in handlers:
raise ValueError('Wrong token type, must be any of %s.' % ', '.join(handlers))
handlers[tok](arg)
|
|
Thank you for the example.