Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #94511 > unrolled thread
| Started by | Neal Becker <ndbecker2@gmail.com> |
|---|---|
| First post | 2015-07-24 12:01 -0400 |
| Last post | 2015-07-24 20:44 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: register cleanup handler Neal Becker <ndbecker2@gmail.com> - 2015-07-24 12:01 -0400
Re: register cleanup handler Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-07-24 20:44 +0000
| From | Neal Becker <ndbecker2@gmail.com> |
|---|---|
| Date | 2015-07-24 12:01 -0400 |
| Subject | Re: register cleanup handler |
| Message-ID | <mailman.953.1437753734.3674.python-list@python.org> |
Laura Creighton wrote:
> In a message of Fri, 24 Jul 2015 10:57:30 -0400, Neal Becker writes:
>>I know we have try/finally, but I don't think that helps here, because
>>code_executed_unconditionally couldn't be inside the try. Or am I missing
>>something obvious?
>
> I think so. Either that or I am badly misunderstanding you. What is
> wrong with
>
> try:
> if (condition):
> do_something_needing_cleanup
> else:
> do_something_else
> code_executed_unconditionally
> finally:
> do_cleanup
>
> Laura
do_cleanup has do be done only if do_something_needing_cleanup was done
first.
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
[toc] | [next] | [standalone]
| From | Rob Gaddi <rgaddi@technologyhighland.invalid> |
|---|---|
| Date | 2015-07-24 20:44 +0000 |
| Message-ID | <mou83b$i05$3@dont-email.me> |
| In reply to | #94511 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web