Re: Allowing ref counting to close file items bad style?

2006-08-31 Thread [EMAIL PROTECTED]
Dan wrote: > BJo:rn Lindqvist wrote: > > On 8/30/06, Dan <[EMAIL PROTECTED]> wrote: > >> Is my data safer if I explicitly close, like this?: > >> fileptr = open("the.file", "w") > >> foo_obj.write(fileptr) > >> fileptr.close() > > Have you ever experienced a problem caused by not exp

Re: Allowing ref counting to close file items bad style?

2006-08-31 Thread Dan
BJörn Lindqvist wrote: > On 8/30/06, Dan <[EMAIL PROTECTED]> wrote: >> Is my data safer if I explicitly close, like this?: >> fileptr = open("the.file", "w") >> foo_obj.write(fileptr) >> fileptr.close() > > Have you ever experienced a problem caused by not explicitly closing > your

Re: Allowing ref counting to close file items bad style?

2006-08-31 Thread BJörn Lindqvist
On 8/30/06, Dan <[EMAIL PROTECTED]> wrote: > Is this discouraged?: > > for line in open(filename): > In theory, it is. In practice, that is the way Python code is written because it more natural and to the point. Not just for hacked together scripts, lots of third party modules incl

Re: Allowing ref counting to close file items bad style?

2006-08-31 Thread [EMAIL PROTECTED]
Paul Rubin wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > > I disagree strongly with this assertion. It's not as efficient overall > > as other GC implementations, but it's not a case of "less efficient to > > do the same task". Reference counting buys you deterministic GC in the > >

Re: Allowing ref counting to close file items bad style?

2006-08-30 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > I disagree strongly with this assertion. It's not as efficient overall > as other GC implementations, but it's not a case of "less efficient to > do the same task". Reference counting buys you deterministic GC in the > pretty common case where you

Re: Allowing ref counting to close file items bad style?

2006-08-30 Thread Matthew Woodcraft
Dan <[EMAIL PROTECTED]> wrote: > Is this discouraged?: > > for line in open(filename): > > > That is, should I do this instead?: > > fileptr = open(filename) > for line in fileptr: > > fileptr.close() One reason to use close() explicitly is to make sure tha

Re: Allowing ref counting to close file items bad style?

2006-08-30 Thread [EMAIL PROTECTED]
Paul Rubin wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > > > > (And personally I think the benefits to programmers of guaranteeing > > > > ref-counting semantics would outweigh the additional headaches for > > > > Jython and other alternative implementations). > > Ref counting is a rat

Re: Allowing ref counting to close file items bad style?

2006-08-30 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > Sure. But most Java GCs are pretty reasonable and for typical code > will run periodically (what I call the not-horribly-distant future). If your system allows max 100 files open and you're using 98 of them, then "horribly distant future" can be a

Re: Allowing ref counting to close file items bad style?

2006-08-30 Thread [EMAIL PROTECTED]
Paul Rubin wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > > I disagree, somewhat. No, you shouldn't count on the "ref count" per > > se going to 0. And you shouldn't count on the file object being GC'd > > _immediately_ after the last reference is destroyed. You should be able > > to

Re: Allowing ref counting to close file items bad style?

2006-08-29 Thread Fredrik Lundh
Dan wrote: > Is this discouraged?: > > for line in open(filename): > > > That is, should I do this instead?: > > fileptr = open(filename) > for line in fileptr: > > fileptr.close() depends on the use case; in a small program that you know will only read

Re: Allowing ref counting to close file items bad style?

2006-08-29 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > I disagree, somewhat. No, you shouldn't count on the "ref count" per > se going to 0. And you shouldn't count on the file object being GC'd > _immediately_ after the last reference is destroyed. You should be able > to rely on it being GC'd at som

Re: Allowing ref counting to close file items bad style?

2006-08-29 Thread [EMAIL PROTECTED]
Paul Rubin wrote: > Dan <[EMAIL PROTECTED]> writes: > > Is this discouraged?: > > > > for line in open(filename): > > > > Yes. > > > Can I count on the ref count going to zero to close the file? > > You really shouldn't. It's a CPython artifact. I disagree, somewhat. No, you shoul

Re: Allowing ref counting to close file items bad style?

2006-08-29 Thread Dan
Paul Rubin wrote: > Dan <[EMAIL PROTECTED]> writes: >> Is this discouraged?: >> >> for line in open(filename): >> > > Yes. Well, not what I wanted to hear, but what I expected. Thanks, Dan -- dedded att verizon dott net -- http://mail.python.org/mailman/listinfo/python-list

Re: Allowing ref counting to close file items bad style?

2006-08-29 Thread Paul Rubin
Dan <[EMAIL PROTECTED]> writes: > Is this discouraged?: > > for line in open(filename): > Yes. > Can I count on the ref count going to zero to close the file? You really shouldn't. It's a CPython artifact. > I understand that the upcoming 'with' statement will obviate this > qu

Allowing ref counting to close file items bad style?

2006-08-29 Thread Dan
Is this discouraged?: for line in open(filename): That is, should I do this instead?: fileptr = open(filename) for line in fileptr: fileptr.close() Can I count on the ref count going to zero to close the file? How about a write case? For example: