Why am I getting a syntax error on the console but not when the same code runs from a script?
<p>Python 2.7.3</p>

<p>From the console:</p>

<pre><code>&gt;&gt;&gt; try:
...     fsock = open("something_that_does_not_exist")
... except IOError:
...     print "The file does not exist"
... print "Let's keep going"
Traceback (  File "&lt;interactive input&gt;", line 5
    print "Let's keep going"
        ^
SyntaxError: invalid syntax
</code></pre>

<p>If I save the same code into a script:</p>

<p><strong>ex.py</strong></p>

<pre><code>def try1():
    try:
        fsock = open("something_that_does_not_exist")
    except IOError:
        print "The file does not exist"
    print "Let's keep going"
</code></pre>

<p>and run it:</p>

<pre><code>&gt;&gt;&gt; import ex
&gt;&gt;&gt; ex.try1()
The file does not exist
Let's keep going
&gt;&gt;&gt; 
</code></pre>

<p>I tried this on the console, IDLE and PythonWin.  Same results.</p>

<p>What's the difference?</p>

<p><strong>EDIT:</strong></p>

<p>I am learning Python with, among other sources, "Dive into Python" (<a href="http://www.diveintopython.net/" rel="nofollow">http://www.diveintopython.net/</a>).  In example 6.1 the author shows exactly this example being run form the command line:  <a href="http://www.diveintopython.net/file_handling/index.html" rel="nofollow">http://www.diveintopython.net/file_handling/index.html</a></p>

<p>That's why I thought this should work. </p>
