title: Check for empty argument Python
body: <p>I'm having two problems with arguments in my program, the first problem is that I'm trying to print an error if no arguments are passed to the program and also I'm trying to instead having to use -n which stands for 'no argument' to actually not have to pass any argument to load the file into the program, I want it to just run like <code>python3 program.py file file2 file3</code> instead of using <code>python3 -n file file2 file3</code> etc.. I have commented out what I tried to check for the argument if the argument is just the program file [0] to exit </p>
  
  <pre><code>def main():
  
      script = sys.argv[0]
      action = sys.argv[1]
      noargfile = sys.argv[1:]
      filenames = sys.argv[2:]
      OutContent = filenames or noargfile
  
      #Load files with arguments -d &amp; --default
      print("Loading Files....", sys.argv[1:])
  
      for arg in filenames:
          try:
              myfile = open(arg, "r")
              fileContent = myfile.readlines()
              myfile.close()
              OutContent = OutContent + fileContent
  
              #if len(sys.argv) == script:
                  #print("No Argument")
                  #sys.exit(0)
  
              if action == '--default':
                  counter = 0 # set a counter to 0 
                  for line in OutContent: #for each line in load if the " 200 " is found add 1 to the counter and repeat until done. 
                      if re.findall(r"\s\b200\b\s", line):
                          counter += 1
                  print("\nTotal of (Status Code) 200 request:", counter)
              elif action == '-d':
                  counter = 0 # set a counter to 0 
                  for line in OutContent: #for each line in load if the " 200 " is found add 1 to the counter and repeat until done. 
                      if re.findall(r"\s\b200\b\s", line):
                          counter += 1
                  print("\nTotal of (Status Code) 200 request:", counter)
              elif action == '-n':
                  menu(arg, OutContent)
          except OSError:
             print("File could not be opened " + filenames)
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>I get an index out of range error, I don't understand why </p>
  
  <pre><code>File "program.py", line 161, in main
      action = sys.argv[1]
  IndexError: list index out of range
  </code></pre>