On 5/12/05, Benji York <[EMAIL PROTECTED]> 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 _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com