Except statement
<p>In a function <code>check_price()</code> I try to open a .txt file, that does not exist, to read and 
I wanted to use except statement to catch the IOerror.</p>

<p>But after, I created a .txt file and I want to use the same function to read it. However my function doesn't read the file. Can anyone help me?</p>

<p>I'm suppose to make a price checker program.</p>

<p>The sample looks like this.</p>

<pre><code>Menu:
(I)nstructions  
(L)oad Products  
(S)ave Products  
(A)dd Product  
(C)heck Prices  
(Q)uit  
&gt;&gt;&gt; C  
No products.  

Menu:  
(I)nstructions  
(L)oad Products  
(S)ave Products  
(A)dd Product  
(C)heck Prices  
(Q)uit  
&gt;&gt;&gt; L  
Enter file name: products.txt  

Menu:  
(I)nstructions  
(L)oad Products  
(S)ave Products  
(A)dd Product  
(C)heck Prices  
(Q)uit  

&gt;&gt;&gt; c  
Huggies is $0.39 per unit.  
Snugglers is $0.26 per unit.  
Baby Love is $0.23 per unit.  
</code></pre>

<p>My function:</p>

<pre><code>def check_price():
        while True:
            try:
                text_file = open("product.txt",'r')
                break
            except IOError:
                print"no product"
                text_file = open("product.txt",'r')
                line = text_file.readline()
                if line == "":
                    break
                print ""
</code></pre>
