Calling len() on an empty (i.e. newly created) FITS adds a HDU:
>>> fits = fitsio.FITS('new.fits', 'rw')
>>> len(fits)
1
>>> 0 in fits
True
>>> fits[-1]
file: test.fits
extension: 0
type: IMAGE_HDU
image info:
The len() call indeed creates the HDU:
>>> fits = fitsio.FITS('another.fits', 'rw')
>>> 0 in fits
False
>>> fits[-1]
ValueError: Requested hdu '-1' not present
This makes the intuitive (well, to me) check len(fits) == 0 for a newly created FITS unusable.
Calling
len()on an empty (i.e. newly created) FITS adds a HDU:The
len()call indeed creates the HDU:This makes the intuitive (well, to me) check
len(fits) == 0for a newly created FITS unusable.