For review: PEP 343: Anonymous Block Redux and Generator Enhancements

Ilpo Nyyssönen iny+news at iki.fi
Sat Jun 4 01:11:08 EDT 2005


Nicolas Fleury <nid_oizo at yahoo.com_remove_the_> writes:

> What about making the ':' optional (and end implicitly at end of current 
> block) to avoid over-indentation?
>
> def foo():
>     with locking(someMutex)
>     with opening(readFilename) as input
>     with opening(writeFilename) as output
>     ...

How about this instead:

with locking(mutex), opening(readfile) as input:
    ...

So there could be more than one expression in one with.

> would be equivalent to:
>
> def foo():
>     with locking(someMutex)
>         with opening(readFilename) as input
>             with opening(writeFilename) as output
>                 ...

The thing is that with normal try-finally block, you can add more
things to it easily. This kind of with thing does not allow adding
more stuff to it in any other way than adding more indentation.

Anyway, I like the idea of the PEP too.

-- 
Ilpo Nyyssönen # biny # /* :-) */



More information about the Python-list mailing list