[Tutor] import sys; sys.exit()

Alan Gauld alan.gauld at btinternet.com
Thu Jan 10 18:33:09 CET 2008

"Andrew Volmensky" <warewerks at verizon.net> wrote

> I am going through the tutorial "Simple Sequences" here: http://
> www.freenetpages.co.uk/hp/alan.gauld/

Good choice ;-)

> ...and get an error. I have tried saving as exit.py from the editor
> and trying to run it

How are you running it?
You need to run it from the Terminal application.
If you are using an IDE environment like IDLE the tool will
catch the attempt to exit and display a warning - which
is what you appear to be seeing.

> and also entering the commands directly into the
> shell.

Again if the shell is the one you get by typing python
at the Terminal prompt it should work and exit python.
But if you are using an IDE prompt such as IDLE then
IDLE will catch the attempt to exit.

> This is with MacPython 2.4 - Thanks!
> IDLE 1.1.4
> >>> ================================ RESTART
> ================================
> >>>
> Traceback (most recent call last):
>   File "/Users/andrew/python/exit.py", line 2, in -toplevel-
>     sys.exit( )
> SystemExit
> >>> import sys
> >>> sys.exit()
> Traceback (most recent call last):
>   File "<pyshell#1>", line 1, in -toplevel-
>     sys.exit()
> SystemExit
> >>>

This looks like the expected behaviour inside IDLE.

I'll add a note to that effect to the web page, thanks for
pointing it out.

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list