[Tutor] Replace try: except: finally:

Stephen Nelson-Smith sanelson at gmail.com
Fri Nov 20 14:08:11 CET 2009


I need to make some code Python 2.4 compliant... the only thing I see
is use of try: except: finally:

To make this valid, I think I need to do a try: finally: and next try:
except: inside.  Is this correct?

The code has;

try:
  ...
  ...
  ...
except SystemExit:
        raise
except KeyboardInterrupt:
        if state.output.status:
            print >> sys.stderr, "\nStopped."
        sys.exit(1)
except:
        sys.excepthook(*sys.exc_info())
        sys.exit(1)
finally:
        for key in connections.keys():
            if state.output.status:
                print "Disconnecting from %s..." % denormalize(key),
            connections[key].close()
            if state.output.status:
                print "done."

How should I replace this?

S.



-- 
Stephen Nelson-Smith
Technical Director
Atalanta Systems Ltd
www.atalanta-systems.com


More information about the Tutor mailing list