title: Calling a function complete with arguments using a dictionary in python3
body: <p>I've been gradually improving my method of calling functions complete with list of arguments held in  dictionary. Where my problem comes in is that the arguments are command line arguments and the functions have varying numbers of arguments. If I call a function that has 2 arguments but the dictionary also has a function with 3, then I will get an &quot;IndexError: list index out of range&quot; re that entry in the dictionary. My code as it stands is</p>
  <h1>!/usr/bin/env python</h1>
  <pre><code>from sys import argv
  
  
  
  def func1(num1, num2):
      result = int(num1) + int(num2)
      print('The sum of {0} and {1} is {2}'.format(num1, num2, result))
  
  def func2(num1, num2, num3):
      result = (int(num1) + int(num2) + int(num3)) / 3
      print('The average of {0} {1} and {2} is {3}'.format(num1, num2, num3, result))
  
  def func3(string1):
      reverse = string1[::-1]
      print('{0} reversed is {1}'.format(string1, reverse))
  
  def func4(*args):
      pass
  
  def func5(*args):
      pass
  
  
  
  def main():
      option = {
          'f1': func1(argv[2], argv[3]),
          'f2': func2(argv[2], argv[3], argv[4]),
          'f3': func3(argv[2])
          }
  
      if len(argv) &gt; 1:
          for routine in option:
              if routine == argv[1]:
                  option[routine]()
                  exit(0)
  
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  <p>I'm on a linux system so if I execute
  ./program.py f1 10 11<br />
  it does give the expected result but throws up said IndexError re the dictionary entry mentioning f2. I could turn the dictionary entry re the function and arguments into a string and use eval but that's unsafe obviously but it does do away with the error. So I gather python is interpreting the dictionary entry as a command and throwing the error. From the above code, does anyone have an idea to get past this problem?</p>