Greg Ewing wrote:
Brian Sabbey wrote:

do f in with_file('file.txt'):
    print f.read()


I don't like this syntax. Try to read it as an English sentence:
"Do f in with file 'file.txt'". Say what???

To sound right it would have to be something like

  with_file('file.txt') as f do:
    print f.read()


This is still strange since f is the arguments the thunk was called with, e.g. the current syntax is basically:


    do <unpack_list> in <returnval> = <callable>(<params>):
        <code>

I don't really know a more readable sequence of keywords, though someone suggested 'with' and 'from', which might read something like:

    with <unpack_list> from <callable>(<params>):
        <code>

which looks okay to me, though I'm not sure that 'with' makes it clear that this is not a normal block... I also find readability problems when I try to stick <returnval> back in.

One of the other issues is that, with the current proposal, the thunk can be called multiple times within a function, so the keywords have to make sense both with a single iteration interpretation and a multiple iteration interpretation... Makes it even harder...

STeVe
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to