when should I explicitely close a file?

2010-04-13 Thread gelonida
Hi, I've been told, that following code snippet is not good. open(myfile,w).write(astring) , because I'm neither explicitely closing nor using the new 'with' syntax. What exactly is the impact of not closing the file explicitely (implicitley with a 'with' block)? Even with my example I'd

Re: when should I explicitely close a file?

2010-04-13 Thread Chris Rebert
On Tue, Apr 13, 2010 at 3:01 PM, gelonida gelon...@gmail.com wrote: Hi, I've been told, that following code snippet is not good. open(myfile,w).write(astring) , because I'm neither explicitely closing nor using the new 'with' syntax. What exactly is the impact of not closing the file

Re: when should I explicitely close a file?

2010-04-13 Thread Steven D'Aprano
On Tue, 13 Apr 2010 15:01:25 -0700, gelonida wrote: Hi, I've been told, that following code snippet is not good. open(myfile,w).write(astring) , because I'm neither explicitely closing nor using the new 'with' syntax. What exactly is the impact of not closing the file explicitely

Re: when should I explicitely close a file?

2010-04-13 Thread Giampaolo Rodola'
What about open('foo', 'w').close(). Does it have the same problems? --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil -- http://mail.python.org/mailman/listinfo/python-list

Re: when should I explicitely close a file?

2010-04-13 Thread Chris Rebert
On Tue, Apr 13, 2010 at 5:45 PM, Giampaolo Rodola' gne...@gmail.com wrote: What about open('foo', 'w').close(). Does it have the same problems? Well, no, but that's only because it's a pointless no-op that doesn't really do anything besides possibly throwing an exception (e.g. if the script

Re: when should I explicitely close a file?

2010-04-13 Thread Dave Angel
gelonida wrote: Hi, I've been told, that following code snippet is not good. open(myfile,w).write(astring) , because I'm neither explicitely closing nor using the new 'with' syntax. What exactly is the impact of not closing the file explicitely (implicitley with a 'with' block)? Even with

Re: when should I explicitely close a file?

2010-04-13 Thread Ryan Kelly
On Tue, 2010-04-13 at 18:19 -0700, Chris Rebert wrote: On Tue, Apr 13, 2010 at 5:45 PM, Giampaolo Rodola' gne...@gmail.com wrote: What about open('foo', 'w').close(). Does it have the same problems? Well, no, but that's only because it's a pointless no-op that doesn't really do anything