[Tutor] Exception handling - syntaxerror?!

Andrei project5 at redrival.net
Sun Sep 25 17:28:12 CEST 2005

> Think the mail system screwed up the formatting! But am fairly sure
> that I have indented it correctly in the console. Try and Except are
> in the column. Any other hints?

Yes :). Compare:

 >>> try:
...   os.system('cls')
... except:
...   print "Foo"
 >>> print "Bar"

With (what you had):

 >>> try:
...   os.system('cls')
... except:
...   print "Foo"
... print "Bar"
   File "<stdin>", line 5
     print "Bar"
SyntaxError: invalid syntax

Subtle, but important difference. You should terminate the try-except 
block (confirm with extra ENTER) before doing more stuff.



Mail address in header catches spam. Real contact info:
''.join([''.join(s) for s in zip(
"poet at aao.l pmfe!Pes ontuei ulcpss  edtels,s hr' one oC.",
"rjc5wndon.Sa-re laed o s npbi ot.Ira h it oteesn edt C")])

More information about the Tutor mailing list