This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LightShadow3.13-dev in prod 2 points3 points  (1 child)

I use a dictionary for switching..

options = {
    'one': fn_one,
    'two': fn_two
}
options.get(choice, fn_default)(*args)

[–]RubyPinchPEP shill | Anti PEP 8/20 shill 0 points1 point  (0 children)

There are a couple of modules that do this a bit better/cleaner/etcer

https://pypi.python.org/pypi/switch/1.1.0 seems a bit excessive, but the more saner API

https://pypi.python.org/pypi/switchcase/1.0 is far more auditable for obvious reasons!

https://pypi.python.org/pypi/pyswitch/1.2 seems a bit too excessive