[Tutor] sys.exit() not working
Sat, 4 Aug 2001 16:30:02 -0400 (EDT)
In the following code sys.exit() fails on the first test (denoted
<---FAILS); but works fine on the second test (denoted <---WORKS).
The only difference I see is that in the second test I provide an error
condition and in the first test I don't. Which brings me to another
question: The error returned if there are no jpg/JPG files in the
directory appears to be a shell error message (RH Linux 7.0) and not a
Python error (because of popen, I presume). If I *need* an error
condition after except, what do I put there (first test)?
What occurs now, if this is run with no jpg/JPG files in the directory, is
the error message for test one gets printed, the test one 'sys.exit()'
gets ignored and the following test gets run. Entering a "return" there
causes that test to fail, and the test 2 error message gets printed and
the file exits to my shell (from whence it was launched).
- fleet -
Creates body of Sylvia's E-bay index. At this point, file sizing must be completed, captions
file must be cleaned up and everything ready to go.
# Get list of .jpg (or .JPG) files
files=string.split(os.popen("ls -1D *.[jJ][pP][gG]").read(),"\012")
print "ls: *.[jJ][pP][gG]: No such file or directory"
sys.exit() #<--- FAILS
# Get captions
captions=string.split(open(raw_input("Enter Captions filename: "),"r").read(),"\012")
print "No such file"
sys.exit() #<--- WORKS
# Compare lengths of files and captions
if len(files) == len(captions):
print "Nr. of files (%s) doesn't match Nr. of captions (%s)" % (len(files), len(captions))
# Create temp.html for insertion into index.html
# The last line in "files" and "captions" is empty; hence len(files)-1
# write filenames and captions to temp.html
for i in range(0,len(files)-1):
temp.write('<li><a href=\"%s\">(%s) - %s</a></li>\n' % (files[i], files[i], captions[i]))
# close temp.html
# get index.html from the mirror directories
os.popen("cp /home/raq2/brickhouse/ebay/index.html /home/dev/brickhouse/ebay")