Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91834 > unrolled thread

Re: for...else

Started byacdr <mail.acdr@gmail.com>
First post2015-06-02 14:52 +0200
Last post2015-06-02 14:52 +0200
Articles 1 — 1 participant

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.


Contents

  Re: for...else acdr <mail.acdr@gmail.com> - 2015-06-02 14:52 +0200

#91834 — Re: for...else

Fromacdr <mail.acdr@gmail.com>
Date2015-06-02 14:52 +0200
SubjectRe: for...else
Message-ID<mailman.57.1433249640.13271.python-list@python.org>
That would work for my example, but it would only really work if all
the calculations are in a nice function. If I just have a block of
code, then I can't use it as easily. (E.g. replace
"complicated_calculation_2()" by multiple lines of code, which I don't
want to shove into a separate function.)

On 6/2/15, Jean-Michel Pichavant <jeanmichel@sequans.com> wrote:
> ----- Original Message -----
>> From: "acdr" <mail.acdr@gmail.com>
>> To: python-list@python.org
>> Sent: Tuesday, 2 June, 2015 1:26:42 PM
>> Subject: for...else
>>
>> Hi,
>>
>> Currently, in various places in my code, I have the equivalent of:
>>
>> for x in it:
>>     if complicated_calculation_1():
>>         cleanup()
>>         break
>>     complicated_calculation_2()
>>     if complicated_calculation_3():
>>         cleanup()
>>         break
>
> Hi
>
> With the following layout, adding calculation steps is just a matter of
> adding a line
>
> for x ion it:
>   for calc, cbk in [
>     (complicated_calculation_1, cleanup),
>     (complicated_calculation_2, None),
>     (complicated_calculation_3, cleanup),
>   ]:
>     if calc() and cbk:
>       cbk()
>       break
>
> It might give you ideas.
>
> JM
>
>
> -- IMPORTANT NOTICE:
>
> The contents of this email and any attachments are confidential and may also
> be privileged. If you are not the intended recipient, please notify the
> sender immediately and do not disclose the contents to any other person, use
> it for any purpose, or store or copy the information in any medium. Thank
> you.
>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web