[Tutor] parsing errors for try/except handling

lonetwin lonetwin@yahoo.com
Fri May 9 03:46:27 2003


Hi all,
      I lurk around here, since I don't do much python these days. This mail, 
however caught my interest. Could some guru (and Brett too if it works for 
him) plz explain this:
> >     try:
> >         tn=telnetlib.Telnet(entry[0])
> >     except error:
> >         response=
> >     else:
> >         tn.read_until('login: ','15')
> >         tn.write(entry[1]+'\n')
> >         tn.read_until('Password: ','15')
> >         tn.write(entry[2]+'\n')
> >         tn.read_until('$','15')
> >         tn.write('ls\n')
> >         response=tn.read_until('$','15')
> >         tn.write('exit\n')
> >     finally:
> >         return response

    I was under the impression that you cannot do a try+except+finally in one 
block. The code should give a SyntaxError while compiling. In fact here's 
what I get on the interpreter:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> try:
...     raise Exception('hell')
... except Exception, msg:
...     print msg
... else:
...     print "foo"
... finally:
  File "<stdin>", line 7
    finally:
          ^
SyntaxError: invalid syntax
>>>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Confused
Steve

-- 
Every silver lining has a cloud around it.