[Python-ideas] adding an __exec__ method to context managers?

Ben Finney ben+python at benfinney.id.au
Tue Oct 13 09:25:25 CEST 2009


Carl Johnson
<cmjohnson.mailinglist at gmail.com> writes:

> So, in this particular case, I think it's more readable to have the
> conditions at the top instead of the bottom.

I'm not understanding “conditions” here. When thinking about programming
languages, a “condition” is an expression evaluated in a boolean
context. You seem to mean something different.

> It's very natural when something that starts as
>
>  for i in range(100):
>     dostuff1(i) # thread safe function
>     dostuff2(i) # not thread safe function
>
> becomes
>
> with parallelize(range(100)) as i:
>     dostuff1(i) # thread safe function
>     dostuff2(i) # not thread safe function
>
> (or some other way of writing the condition at the top instead of,
> such as a decorator etc.) instead of
>
> def f(i):
>     dostuff1(i) # thread safe function
>     dostuff2(i) # not thread safe function
>
> parallelize(f, range(100))
>
> with the loop condition at the bottom.

I'm not seeing how you got from the “start as” case to the latter cases.
Where is the loop condition?

-- 
 \     “Whatever a man prays for, he prays for a miracle. Every prayer |
  `\   reduces itself to this: “Great God, grant that twice two be not |
_o__)                                           four.”” —Ivan Turgenev |
Ben Finney




More information about the Python-ideas mailing list