python try-except
<p>I have this code:</p>

<pre><code>#! /usr/bin/python
import sys, string

def findAll(search, fh):
    count = 0
    for line in fh:
        count += 1
        if line.find(search) != -1:
            print "%3d: %s"%(count, line.rstrip())
    return count

search = raw_input("Enter string to be found: ")
filename = raw_input("Enter filename: ")
fh = open(filename, "rU")
findAll(search, fh)
</code></pre>

<p>My professor recommended I write this code and incorporate "improved usage".<br>
I'm confused as to how but she recommended that</p>

<ol>
<li><p>I modify the program by commenting out the <code>raw_input()</code> statements, then adding statements to check if the program is invoked with fewer than 2 arguments and if so to <code>print 'Usage: findstring.py string filename</code>. The code takes strings and locates them in a file.  </p></li>
<li><p>I use the <code>filename</code> command line argument from <code>sys.argv</code> to open the file and prepare for an input/output error (IOError) to occur. Then to use a <code>try-except</code> block to encode what to do if opening the file works or not.<br>
If the opening fails, I <code>print 'Error: cannot open findstring.py</code> where <code>findstring.py</code> is also the considered the text file.  </p></li>
</ol>

<p>To be honest... I was so busy writing down her suggestions that I had no idea how to do many of the things she recommended. Can someone help improve this code? I'm confused and I don't know how to do this. My prof did say that the code would run, but I don't know how to modify it.  </p>
