pre-PEP: Simple Thunks

Serhiy Storchaka storchaka at ksf.kiev.ua
Mon Apr 18 11:30:50 EDT 2005


Brian Sabbey wrote:
> do f in with_file('file.txt'):
>     print f.read()

def with_file(filename):
     f = open(filename)
     yield f
     f.close()

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

> t = "no file read yet"
> do f in with_file('file.txt'):
>     t = f.read()

t = "no file read yet"
for f in with_file('file.txt'):
     t = f.read()

--
Serhiy Storchaka



More information about the Python-list mailing list