Function closure inconsistency

2010-07-23 Thread SeanMon
I was playing around with Python functions returning functions and the
scope rules for variables, and encountered this weird behavior that I
can't figure out.

Why does f1() leave x unbound, but f2() does not?

def f1():
x = 0
def g():
x += 1
return x
return g1

def f2():
x = []
def g():
x.append(0)
return x
return g

a = f1()
b = f2()

a() #UnboundLocalError: local variable 'x' referenced before
assignment
b() #No error, [0] returned
b() #No error, [0, 0] returned
-- 
http://mail.python.org/mailman/listinfo/python-list


Decompressing gzip over FTP

2009-08-21 Thread SeanMon
Is there a way to decompress a large (2GB) gzipped file being
retrieved over FTP on the fly?

I'm using ftplib.FTP to open a connection to a remote server, and I
have had no success connecting retrbinary to gzip without using an
intermediate file.

Is there any way to get a file-like object describing the remote file,
or a way to utilize gzip's decompression without providing it a file-
like object?

Thanks,
Sean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decompressing gzip over FTP

2009-08-21 Thread SeanMon
On Aug 21, 9:40 pm, Christian Heimes  wrote:
> SeanMon schrieb:
>
> > Is there a way to decompress a large (2GB) gzipped file being
> > retrieved over FTP on the fly?
>
> > I'm using ftplib.FTP to open a connection to a remote server, and I
> > have had no success connecting retrbinary to gzip without using an
> > intermediate file.
>
> > Is there any way to get a file-like object describing the remote file,
> > or a way to utilize gzip's decompression without providing it a file-
> > like object?
>
> gzip is really just a file format. In order to work with compressed
> streams you should use the low level zlib module.
>
> http://docs.python.org/library/zlib.html#module-zlib
>
> Have fun!
>
> Christian

Unfortunately, the file on the server is a gzip file, so I cannot
simply pipe the contents into a zlib.decompressobj (which does have
the ability to decompress in chunks, as I wish gzip did!).

Thanks,
Sean
-- 
http://mail.python.org/mailman/listinfo/python-list