Python ValueError exception - Name "a" is not defined error
<p>I am trying to implement a try exception in Python which when inputting a char/string instead of an int, catches the exception. </p>

<p>However, when inputting the letter 'a' the program crashes, returning the following error:</p>

<pre><code>num = input('Enter integer number: ')   File "&lt;string&gt;", line 1, in
&lt;module&gt; NameError: name 'a' is not defined
</code></pre>

<p>This is my code:</p>

<pre><code>if __name__ == '__main__':   #main function
    num = input('Enter integer number: ')
    try:
        num = int(num)
    except ValueError:
        print "Invalid input."
</code></pre>