Return value of an assignment statement?
Arnaud Delobelle
arnodel at googlemail.com
Sat Feb 23 12:11:43 EST 2008
On Feb 23, 3:44 pm, Jeff Schwab <j... at schwabcenter.com> wrote:
>
> actions = (
> ('some_string', do_something),
> ('other_string', do_other_thing))
>
> def find_action(pattern):
> for string, action in actions:
> m = pattern.match(string)
> if m:
> return action
> return do_default_thing
>
> find_action(re.compile('some pattern'))()
You don't need to pass the pattern, just pass the match function:
def find_action(match, actions=actions, default_action=None):
for string, action in actions:
if match(string):
return action
return default_action
find_action(re.compile('some pattern').match)()
--
Arnaud
More information about the Python-list
mailing list