Re: File not closed

2019-03-20 Thread DL Neil
On 2019-03-20, ast wrote: In the following snippet, a file is opened but without any variable referring to it. So the file can't be closed. [line.split(":")[0] for line in open('/etc/passwd') if line.strip() and not line.startswith("#")] What do you think about this practice ? As other

Re: File not closed

2019-03-20 Thread Chris Angelico
On Thu, Mar 21, 2019 at 1:16 AM Grant Edwards wrote: > > On 2019-03-20, ast wrote: > > Hello > > > > In the following snippet, a file is opened but > > without any variable referring to it. > > So the file can't be closed. > > > > [line.split(":")[0] > > for line in open('/etc/passwd') > > if

Re: File not closed

2019-03-20 Thread Grant Edwards
On 2019-03-20, ast wrote: > Hello > > In the following snippet, a file is opened but > without any variable referring to it. > So the file can't be closed. > > [line.split(":")[0] > for line in open('/etc/passwd') > if line.strip() and not line.startswith("#")] > > What do you think about this

Re: File not closed

2019-03-20 Thread Peter Otten
ast wrote: > Hello > > In the following snippet, a file is opened but > without any variable referring to it. > So the file can't be closed. The file will be closed implicitly when the file object gets garbage- collected: $ python3 Python 3.4.3 (default, Nov 12 2018, 22:25:49) [GCC 4.8.4] on l

File not closed

2019-03-20 Thread ast
Hello In the following snippet, a file is opened but without any variable referring to it. So the file can't be closed. [line.split(":")[0] for line in open('/etc/passwd') if line.strip() and not line.startswith("#")] What do you think about this practice ? -- https://mail.python.org/mailm

Re: File not closed on exception

2009-10-20 Thread arve.knud...@gmail.com
On 20 Okt, 21:13, "Gabriel Genellina" wrote: > En Tue, 20 Oct 2009 04:47:02 -0300, arve.knud...@gmail.com   > escribió: > > > On 20 Okt, 09:40, "Gabriel Genellina" wrote: > >> En Tue, 20 Oct 2009 03:23:49 -0300, arve.knud...@gmail.com   > >> escribió: > >> > I agree, but like I said, I've been

Re: File not closed on exception

2009-10-20 Thread Gabriel Genellina
En Tue, 20 Oct 2009 04:47:02 -0300, arve.knud...@gmail.com escribió: On 20 Okt, 09:40, "Gabriel Genellina" wrote: En Tue, 20 Oct 2009 03:23:49 -0300, arve.knud...@gmail.com escribió: > I agree, but like I said, I've been told that this (implicit closing > of files) is the correct style b

Re: File not closed on exception

2009-10-20 Thread arve.knud...@gmail.com
On 20 Okt, 16:00, Bruno Desthuilliers wrote: > What's your problem with the with ??? No problem whatsoever, but I believe I wrote this utility function before the keyword was available, and it might be good to support older Python versions. > But anyway : explicitely releasing resources such as

Re: File not closed on exception

2009-10-20 Thread Bruno Desthuilliers
arve.knud...@gmail.com a écrit : On Oct 19, 4:14 pm, Grant Edwards wrote: On 2009-10-19, arve.knud...@gmail.com wrote: I thought that file objects were supposed to be garbage-collected and automatically closed once they go out of scope, At some point after they go out of scope, they will be

Re: File not closed on exception

2009-10-20 Thread Ethan Furman
arve.knud...@gmail.com wrote: On Oct 19, 3:48 pm, Ethan Furman wrote: arve.knud...@gmail.com wrote: Hi I thought that file objects were supposed to be garbage-collected and automatically closed once they go out of scope, at least that's what I've been told by more merited Python programme

Re: File not closed on exception

2009-10-20 Thread Mel
arve.knud...@gmail.com wrote: > I agree, but like I said, I've been told that this (implicit closing > of files) is the correct style by more merited Python developers, so > that made me think I was probably wrong .. It would be nice. The trouble is that CPython is not the only Python. Jython,

Re: File not closed on exception

2009-10-20 Thread Ulrich Eckhardt
arve.knud...@gmail.com wrote: > On Oct 19, 3:48 pm, Ethan Furman wrote: >> arve.knud...@gmail.com wrote: [...] >>> def create(): >>> f = file("tmp", "w") >>> raise Exception >>> >>> try: >>> create() >>> finally: >>> os.remove("tmp") >>> [...] >> When an exception is raised, the e

Re: File not closed on exception

2009-10-20 Thread arve.knud...@gmail.com
On 20 Okt, 09:40, "Gabriel Genellina" wrote: > En Tue, 20 Oct 2009 03:23:49 -0300, arve.knud...@gmail.com   > escribió: > > > > > > > On Oct 19, 5:56 pm, "Gabriel Genellina" > > wrote: > >> En Mon, 19 Oct 2009 09:45:49 -0200, arve.knud...@gmail.com   > >> escribió: > > >> > I thought that file

Re: File not closed on exception

2009-10-20 Thread Gabriel Genellina
En Tue, 20 Oct 2009 03:23:49 -0300, arve.knud...@gmail.com escribió: On Oct 19, 5:56 pm, "Gabriel Genellina" wrote: En Mon, 19 Oct 2009 09:45:49 -0200, arve.knud...@gmail.com   escribió: > I thought that file objects were supposed to be garbage-collected and > automatically closed once they

Re: File not closed on exception

2009-10-19 Thread arve.knud...@gmail.com
On Oct 19, 5:56 pm, "Gabriel Genellina" wrote: > En Mon, 19 Oct 2009 09:45:49 -0200, arve.knud...@gmail.com   > escribió: > > > I thought that file objects were supposed to be garbage-collected and > > automatically closed once they go out of scope, at least that's what > > I've been told by more

Re: File not closed on exception

2009-10-19 Thread arve.knud...@gmail.com
On Oct 19, 4:14 pm, Grant Edwards wrote: > On 2009-10-19, arve.knud...@gmail.com wrote: > > > I thought that file objects were supposed to be > > garbage-collected and automatically closed once they go out of > > scope, > > At some point after they go out of scope, they will be. > Eventually.  Ex

Re: File not closed on exception

2009-10-19 Thread arve.knud...@gmail.com
On Oct 19, 3:48 pm, Ethan Furman wrote: > arve.knud...@gmail.com wrote: > > Hi > > > I thought that file objects were supposed to be garbage-collected and > > automatically closed once they go out of scope, at least that's what > > I've been told by more merited Python programmers. I'm also quite

Re: File not closed on exception

2009-10-19 Thread Gabriel Genellina
En Mon, 19 Oct 2009 09:45:49 -0200, arve.knud...@gmail.com escribió: I thought that file objects were supposed to be garbage-collected and automatically closed once they go out of scope, at least that's what I've been told by more merited Python programmers. An object (any object) is destro

Re: File not closed on exception

2009-10-19 Thread Grant Edwards
On 2009-10-19, arve.knud...@gmail.com wrote: > I thought that file objects were supposed to be > garbage-collected and automatically closed once they go out of > scope, At some point after they go out of scope, they will be. Eventually. Exactly when is an implementation detail. > at least that

Re: File not closed on exception

2009-10-19 Thread Ethan Furman
arve.knud...@gmail.com wrote: Hi I thought that file objects were supposed to be garbage-collected and automatically closed once they go out of scope, at least that's what I've been told by more merited Python programmers. I'm also quite sure that this is quite a common assumption in various pro

File not closed on exception

2009-10-19 Thread arve.knud...@gmail.com
Hi I thought that file objects were supposed to be garbage-collected and automatically closed once they go out of scope, at least that's what I've been told by more merited Python programmers. I'm also quite sure that this is quite a common assumption in various programs, at least given what opens