[AstroPy] pyfits does not write to gzip ab+ objects
embray at stsci.edu
Mon Sep 9 19:02:37 EDT 2013
On 08/23/2013 01:49 AM, John K. Parejko wrote:
> On python2.7/pyfits3.1.2 , when I try to write to a gzip object in append mode, 'ab+', I receive an IOError: [Errno 9] read() on write-only GzipFile object. Whereas when I use mode 'ab', I receive no error.
> The former worked in pyfits 2.4-ish (what we were previously using). We use NamedTemporaryFiles to prevent accidental filename collision, and pass that through a gzip object to select the compression level, before writing with hdu.writeto(tempFile,checksum=True).
> I'm not sure whether pyfits or gzip is really the culprit here. I've attached an example.
> Thanks in advance,
I was just taking another look at this because I've been working on refactoring
some of the file handling code in pyfits. And one thing that I noticed is that
the `writeto()` method was only ever really designed for writing out a *new*
file, and doesn't support appending to an existing file. Now, it should still
accept a file with 'ab+' mode and just write a new file (so long as a file with
the given name doesn't already exist). But in the case that the file doesn't
already exist there's no reason to use append mode. Just 'wb' should be fine.
> # Example:
> import gzip
> import pyfits
> import numpy as np
> #IOError: [Errno 9] read() on write-only GzipFile object
> #works, resulting file is gzipped.
> AstroPy mailing list
> AstroPy at scipy.org
More information about the AstroPy