title: IndexError: list index out of range Python Argument Input
body: <pre><code>import sys
  #print sys.argv[1]
  def IndexSearchString():
  
  
      This function search a string in a file through index and gives the result.
  
  
  
      #fieldindex = int(sys.argv[1])-1
      stringsrch = sys.argv[2]
      #size = len(sys.argv)
      file_name = open("passwd", "r")
      #print "No of Argu ", size
      ''' 
      if sys.argv[1] == Null:
          print "Please enter argument"   
      '''
      if sys.argv[1].isdigit():
          fieldindex = int(sys.argv[1])-1
      else:
          print "Enter integer in 1st Argument"
          sys.exit(1)
      fieldindex = int(sys.argv[1])-1
  
      stringsrch = sys.argv[2]
  
      if len(sys.argv) &gt; 3 :
          print "Enter two arguments only"
          sys.exit(1)
  
      for store_file in file_name:
          temp = store_file.split(":")
          search = temp[fieldindex]
          #print search 
  
          if stringsrch in search:
              print store_file
  
  IndexSearchString()
      '''
      My Question is:
      I am taking two argument in the command line. Now I want to handle when only one     argument is given and also when no argument is given.
      Help me out 
  
      Error:
      Command Window Input: python SearchString.py 1 
      Traceback (most recent call last):
      File "SearchString.py", line 46, in &lt;module&gt;
      IndexSearchString() 
      File "SearchString.py", line 36, in IndexSearchString
      stringsrch = sys.argv[2]
      IndexError: list index out of range
      '''
  </code></pre>