On Fri, 24 Jul 2015 12:01:58 -0400, Neal Becker wrote:

> 
> This would work, but is not very elegant.  I hope for a better way.
> 
> need_cleanup = False try:
>    if (condition):
>       do_something_needing_cleanup need_cleanup = True
>    else:
>       do_something_else
>    code_executed_unconditionally
> finally:
>    if need_cleanup:
>      do_cleanup

if condition:
  try:
    do_something_needing_cleanup()
    code_executed_unconditionally()
  finally:
    do_cleanup()

else:
  do_something_else()
  code_executed_unconditionally()



-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to