[Python-Dev] Merging PEP 310 and PEP 340-redux?
Michele Simionato
michele.simionato at gmail.com
Thu May 12 17:34:57 CEST 2005
On 5/12/05, Benji York <benji at zope.com> wrote:
> if the file object had these methods:
>
> def __enter__(self): return self
> def __exit__(self, *args): self.close()
>
> you could write
>
> do file('whatever) as f:
> lines = f.readlines()
>
> Or a lock:
>
> def __enter__(self): self.aquire(); return self
> def __exit__(self, *args): self.release()
>
> do my_lock:
> a()
> b()
> c()
Ah, finally a proposal that I can understand!
But maybe the keyword should be "let":
let lock:
do_something
let open("myfile") as f:
for line in f: do_something(line)
or even, without need of "as":
let f=file("myfile") :
for line in f: do_something(line)
which I actually like more
Michele Simionato
More information about the Python-Dev
mailing list