struggling to implement a switch/case statement in python
<p>since there is no <code>switch/case</code> in python, i am trying to implement the same in my sample program with the help of the following link:
<a href="http://www.pydanny.com/why-doesnt-python-have-switch-case.html" rel="nofollow">why python doesnt have switch-case</a></p>

<p>below is my code:</p>

<pre><code>#switch case to get the type of action to take
def action_type(action_id, dir_path):
    switcher = {
        1: func1(dir_path),
        2: func2(dir_path),
    }
    action_func = switcher.get(action_id, "Do Nothing")
    print "action_func, ", action_func
    sys.exit(0)
    return action_func()
</code></pre>

<p>now it always goes to func1 irrespective of the argument i.e. action_id passed</p>

<p>When you call <code>switcher.get(action_id, sys.exit(0))</code>, the 2nd argument is evalulated before the result can be passed in to <code>.get()</code>, which results in the program terminating immediately.</p>

python