title: Python Command Line Arguments Try/Except
body: <p>I want to create a program that will take two command line arguments. The first being the name of a file to open for parsing and the second the flag -s. If the user provides the wrong number of arguments or the other argument is not -s then it will print the message "Usage: [-s] file_name" and terminate the program using exit. </p>
  
  <p>Next, I want my program to attempt to open the file for reading. The program should open the file read each line and return a count of every float, integer, and other kinds of strings that are not ints or floats. However, if opening the file fails it should raise an exception and print "Unable to open [filename]" and quit using exit.  </p>
  
  <p>I've been looking up lots of stuff on the internet about command lines in Python but I've ended up more confused. So here's my attempt at it so far from what I've researched. </p>
  
  <pre><code>    from optparse import OptionParser  
  
      def command_line():
          parser = OptionParser()        
          parser.add_option("--file", "-s")                             
  
          options, args = parser.parse_args()
          if options.a and obtions.b:
              parser.error("Usage: [-s] file_name")
  
              exit
  
      def read_file():
          #Try:
              #Open input file
          #Except:
              #print "Unable to open [filename]"
              #Exit
  </code></pre>