title: How to call a function inside a dictionary in python
body: <p>I am creating a python shell script that will allow the user to enter commands that output a string. But also some commands will call a function, like <strong>help</strong>, or <strong>exit</strong> 
  I know python does not have a switch case so I am using a dictionary instead, as I do not want to use if and else statements  </p>
  
  <p><strong>The problem:</strong></p>
  
  <p>The problem is I cannot use a function call inside the dictionary with the way I have it implemented as it expects to output a string, so when I enter <strong>help</strong>
  I get an error</p>
  
  <pre><code>    #!/usr/bin/python
  
      x = 0
      while x == 0:
  
  
  
          def helpCommand():
              print "this will help you"
  
          switcher = {
             "url": " the url is: ... ",
             "email": " my email is: ...",
             "help": helpCommand,
             "exit": exit,
          }
  
          choice = raw_input("enter your command choice: ")
  
          def outputChoice(choice)
              return switcher.get(choice)
  
          print outputChoice(choice)
  </code></pre>
  
  <p>I tried to solve this problem by using function call instead, but now I get an error when trying to call a string</p>
  
  <pre><code> def outputChoice(choice)
                      return switcher[choice]()
  </code></pre>
  
  <blockquote>
    <p>TypeError: 'str' object is not callable</p>
  </blockquote>
  
  <p>How to fix this problem ?</p>