Invalid Syntax Error
Ray Holt
mrholtsr at sbcglobal.net
Thu Jan 14 14:43:53 EST 2010
Why am I getting an invalid systax on the first except in the following
code. It was copid from the python tutorial for beginners. Thanks, Ray
import sys
try:
#open file stream
file = open(file_name, "w"
except IOError:
print "There was an error writing to", file_name
sys.exit()
print "Enter '", file_finish,
print "' When finished"
while file_text != file_finish:
file_text = raw_input("Enter text: ")
if file_text == file_finish:
# close the file
file.close
break
file.write(file_text)
file.write("\n")
file.close()
file_name = raw_input("Enter filename: ")
if len(file_name) == 0:
print "Next time please enter something"
sys.exit()
try:
file = open(file_name, "r")
except IOError:
print "There was an eror reading file"
sys.exit
file_text = file.read()
file.close
print file_text
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100114/35b5ace0/attachment.html>
More information about the Python-list
mailing list