pre-PEP: Simple Thunks

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Apr 19 23:38:18 EDT 2005


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()

But, while that works with this particular function
name, and others of the form "with_xxx", there are
bound to be other use cases which would require
different words or word orders in order not to sound
contrived.

It's very difficult to come up with a good syntax for
this that isn't skewed towards one kind of use case.
That's probably a large part of the reason why nothing
like it has so far been seriously considered for
adoption.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list