Robert Kern wrote:

>> probably something like this: (untested)
>>     def make_ftplib_callback(f):
>>         def callback(block): f.write(block)
>>         return callback
>>     img = cStringIO.StringIO()
>>     retrbinary( "get ???", make_ftplib_callback(img))
>
> Ummm, how about
>
> img = cStringIO.StringIO()
> retrbinary("get ???", img.write)

if you want some additional code to run during download, you can
always do something like:

    img = cStringIO.StringIO()
    def callback(block):
        sys.stdout.write(".")
        img.write(block)
        if img.tell() > LIMIT:
            raise IOError("too much data")
    retrbinary(..., callback())

(you don't really have to create a factory if all you need is a single
function...)

you can also get rid of the cStringIO module :

    img = []
    retrbinary(..., img.append)
    # img is now a list of string chunks

might be more efficient, depending on what you plan to do with the
data once you've loaded it.

and finally,

    img = urllib.urlopen("ftp://...";).read()

might also work.

</F> 



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to