Exiting out of a program through a menu option
<p>I need to say first and foremost, I am just learning Python.  </p>

<p>I am making a simple python program that has a menu option for exiting the program by using a function I called exit.  I have tried making the exit function just call break, but I am getting an error when the exit function is called.</p>

<p>Any help would be greatly appreciated.</p>

<p>Sorry for not posting code earlier....</p>

<pre><code>def exit():
    break


evade = evade_fw()

# Main program running dialogue
def main():  # menu goes here
    opt_list = [xsl_file,
                basic_loud_scan,
                fw_main,
                exit
                ]
</code></pre>

<p>Just forget about your own <code>exit()</code> function. You can simply do:</p>

<pre><code>from sys import exit
</code></pre>

<p>And the <code>exit()</code> function from <code>sys</code> module will do the job.<br>
It's also worth to know what happens under the hood. Function <code>sys.exit()</code> actually throws a special exception. You can do it as well explicitly and without importing anything:</p>

<pre><code>raise SystemExit()
</code></pre>

python menu exit