The function below based on the Python sample code in the Python gzip module docs. It runs reliably on Ubuntu 10.04 with its default Python 2.6.x. On Ubuntu 11.04, however, the code fails @ writelines().
On one 11.04 machine, the failure message reported 'module' object has no attribute 'BufferedIOBase'. Another 11.04 machine reported a different message No module named numpy. Yet, the numpy package is installed on both machines.
Does anyone know of any missing Python dependencies or other problems on 11.04 that would cause this?
def _compress(inp,out):
import gzip
f_out = gzip.open(out,'wb')
f_in = open(inp,'rb')
f_out.writelines(f_in)
f_out.close()
f_in.close()
os.unlink(inp)
The error message
No module named numpyis unrelated to this problem; some other bug is causing this. To track this down, print the value ofsys.pathto see which paths Python would search for a module. Numpy might be installed but maybe not in a place included insys.path. That out of the way, back to your main issue.Check the Python version. My guess is that 11.04 comes with 2.7.x.
writelines()is an odd method to call for binary data. Even worse, the parameter should be a sequence of strings, not a file object. Try this code instead:Depending on the file size, this eats a lot of memory. Try a loop instead: