How do you FTP ASCII if ftplib strips CR?

echuck at mindspring.com echuck at mindspring.com
Tue Jun 13 21:06:57 EDT 2000


In article <uog55mk6r.fsf at ctwd0143.fitlinxx.com>,
  David Bolen <db3l at fitlinxx.com> wrote:
> > ourFTP.retrlines('RETR ' + filename, open(os.path.join(localdir,
> > filename), 'w').write)
>
> Your problem is using the "write" method on a file, which just writes
> a buffer of data without any consideration for text "lines".  As an
> aside, note that by doing the open inside the retrlines() call
> that you lost access to the open object, and thus can't close() it.
> It's possible that some data may not get flushed to the file until
> your process exits.  I'd probably open the file separately and close
> it after the retrieval.

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.

-Chuck
--
http://webware.sourceforge.net


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list