Skip to content

calling len() adds a HDU to an empty FITS #348

Description

@ntessore

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions