How do you FTP ASCII if ftplib strips CR?

David Bolen db3l at fitlinxx.com
Wed Jun 14 00:06:30 EDT 2000


echuck at mindspring.com writes:

> By losing access to the file object returned by open(), it gets gc'ed
> and therefore closed and flushed immediately. You only have to worry
> about standalone open() calls if you use JPython or think you will
> someday.

What about some newer version of CPython or some alternative to either
CPython or JPython?  Although of course you're right that without the
reference an implementation is free to GC (and CPython will), it's not
guaranteed - in fact it's specifically permitted not to happen in the
language reference.

But I'll fess up - my mind was partially thinking about scoping when I
was writing (expecting the object to be destroyed when the script
ended) :-)

Even with immediate GC, I don't believe there's anything documented
that implies the destructor for a file object must close() the object,
but it's of course a reasonable assumption.  I still think its safer
all around to be explicit when handling files, and take responsibility
for closing them when done.  Besides, what happens if the close fails?
A previous co-worker had an interesting data-loss bug related to not
checking return codes on close() :-)

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list