Sandra-24 wrote: > I was reading over some python code recently, and I saw something like > this: > > contents = open(file).read() > > And of course you can also do: > > open(file, "w").write(obj) > > Why do they no close the files? Is this sloppy programming or is the > file automatically closed when the reference is destroyed (after this > line)? I usually use: > > try: > f = open(file) > contents = f.read() > finally: > f.close() >
this above is equivalent to: open(file){|f| contents=f.read } the logic taking care of everything is encapsulated in open. but can be done in less ruby way way :) lopex -- http://mail.python.org/mailman/listinfo/python-list