Python: Retorno en bloque try-except-finally

Bueno saberlo:

En Python se puede tener un bloque try-except-finally, retornar en except y aún así el código finally es ejecutado. Genial!

>>> def function():
...     try:
...         raise Exception()
...     except:
...         return True
...     finally:
...         print 'Finally executed'
...
>>> function()
Finally executed
True
Advertisement
  1. Aún no hay trackbacks

Deja un comentario

Fill in your details below or click an icon to log in:

Logo de WordPress.com

You are commenting using your WordPress.com account. Log Out / Cambiar )

Twitter picture

You are commenting using your Twitter account. Log Out / Cambiar )

Facebook photo

You are commenting using your Facebook account. Log Out / Cambiar )

Connecting to %s

Seguir

Get every new post delivered to your Inbox.