{"action":"created","issue":{"url":"https://api.github.com/repos/spacetelescope/PyFITS/issues/108","repository_url":"https://api.github.com/repos/spacetelescope/PyFITS","labels_url":"https://api.github.com/repos/spacetelescope/PyFITS/issues/108/labels{/name}","comments_url":"https://api.github.com/repos/spacetelescope/PyFITS/issues/108/comments","events_url":"https://api.github.com/repos/spacetelescope/PyFITS/issues/108/events","html_url":"https://github.com/spacetelescope/PyFITS/issues/108","id":146355980,"number":108,"title":"No code for getting number of extentions","user":{"login":"pietrow","id":18311216,"avatar_url":"https://avatars.githubusercontent.com/u/18311216?v=3","gravatar_id":"","url":"https://api.github.com/users/pietrow","html_url":"https://github.com/pietrow","followers_url":"https://api.github.com/users/pietrow/followers","following_url":"https://api.github.com/users/pietrow/following{/other_user}","gists_url":"https://api.github.com/users/pietrow/gists{/gist_id}","starred_url":"https://api.github.com/users/pietrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pietrow/subscriptions","organizations_url":"https://api.github.com/users/pietrow/orgs","repos_url":"https://api.github.com/users/pietrow/repos","events_url":"https://api.github.com/users/pietrow/events{/privacy}","received_events_url":"https://api.github.com/users/pietrow/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-06T15:48:10Z","updated_at":"2016-04-06T16:50:32Z","closed_at":"2016-04-06T16:50:32Z","body":"There should be a way to get the number of extensions of a fits file, you'd expect HDUList to be able to do that. \r\n\r\nSomething like this might be handy. \r\n\r\n```\r\ndef nextentions(im):\r\n    '''\r\n    Returns the number of extentions inside of a fits file.\r\n    \r\n    INPUT: im - filepath to fits file.\r\n    OUTPUT: number of extentions in the file.    \r\n    '''\r\n    i = 0\r\n    fit = pyfits.open(im)\r\n    while True:\r\n        try:\r\n            trythis = fit[i].header\r\n\r\n        except IndexError:\r\n            fit.close()\r\n            return i\r\n        i+=1\r\n```"},"comment":{"url":"https://api.github.com/repos/spacetelescope/PyFITS/issues/comments/206461653","html_url":"https://github.com/spacetelescope/PyFITS/issues/108#issuecomment-206461653","issue_url":"https://api.github.com/repos/spacetelescope/PyFITS/issues/108","id":206461653,"user":{"login":"pllim","id":2090236,"avatar_url":"https://avatars.githubusercontent.com/u/2090236?v=3","gravatar_id":"","url":"https://api.github.com/users/pllim","html_url":"https://github.com/pllim","followers_url":"https://api.github.com/users/pllim/followers","following_url":"https://api.github.com/users/pllim/following{/other_user}","gists_url":"https://api.github.com/users/pllim/gists{/gist_id}","starred_url":"https://api.github.com/users/pllim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pllim/subscriptions","organizations_url":"https://api.github.com/users/pllim/orgs","repos_url":"https://api.github.com/users/pllim/repos","events_url":"https://api.github.com/users/pllim/events{/privacy}","received_events_url":"https://api.github.com/users/pllim/received_events","type":"User","site_admin":false},"created_at":"2016-04-06T16:50:32Z","updated_at":"2016-04-06T16:50:32Z","body":"@philhodge 's answer is the way to go.\r\n\r\nBy the way, PyFITS is deprecated. Please use `astropy.io.fits`. See http://astropy.readthedocs.org/en/stable/io/fits/index.html for details."}}