stop()/_quit()

T

Thomas Philips

I attempt to open a writeable file inside some nested loops, and want
my program to terminate cleanly with an error message if it cannot
find the file's path (e.g. directory does not exist). So I write

try: outFile = file(outFileName, "w")
except IOError:
print "The output file",outFileName,"cannot be created."
_quit()

but when I run the code in IDLE, I get

The output file c:\python23\programs\Ford\PaLGUVMO20\PaLGUVMO20.91c
cannot be created.

Traceback (most recent call last):
File "C:\Python23\Programs\ford1.py", line 109, in -toplevel-
main()
File "C:\Python23\Programs\ford1.py", line 66, in main
_quit()
NameError: global name '_quit' is not defined

I've tried stop() instead of _quit(), with similar results. break does
not do the job - it just breaks out of the innermost loop and the
outer loops keep running. What's the fix?

Thomas Philips
 
R

Russell Blau

Thomas Philips said:
NameError: global name '_quit' is not defined

I've tried stop() instead of _quit(), with similar results. break does
not do the job - it just breaks out of the innermost loop and the
outer loops keep running. What's the fix?

Ummm, the error message might be a clue -- you could try *defining* _quit.

Or, you could use the standard library function sys.exit(), making sure you
import sys first.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,635
Latest member
SkyePurves

Latest Threads

Top