Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if filename is a file object, fitslib.extract_filename gets the file nam... #3

Closed
wants to merge 1 commit into from

Conversation

montefra
Copy link

...e string.

can be useful when, e.g., input and/or output file names are opened for checks (e.g. argparse.FileType)

@montefra
Copy link
Author

I didn't think about the problems on consistency.
In pyfits its possible to use an object file. I can try to give a look at their code in the next days.

@esheldon
Copy link
Owner

pyfits is python only so it is easy to deal with. In fitsio I use cfitsio for file handling, which is a C code. cfitsio does not know anything about python file objects, so all the logic would have to be created to make sure this works.

@montefra
Copy link
Author

it looks like in python 2.6 and 2.7 it is possible to convert file objects into c FILE* with PyFile_AsFile. I hope to have some time in the next days to dig into it a bit more. At worse I'll come back to the issue next year.

@esheldon
Copy link
Owner

The problem goes deeper than that, as cfitsio doesn't like to take FILE* objects, at least not the examples I have seen.

@montefra
Copy link
Author

I finally found the time to check how the structure "fitsfile", the "structure that CFITSIO uses to store relevant parameters about each opened file"[1]. There is no FILE variable in this structure, so you where right.

Anyway if you think that adding a check on file objects make sense, I could do something like:

if( type(filename) == file ):
    filename = filename.name
    file.close()

Otherwise lets just close and forget this pull request

[1]http://heasarc.gsfc.nasa.gov/docs/software/fitsio/quick/node7.html

@esheldon
Copy link
Owner

I think it would be surprising if a user input a file object and it was closed by fitsio. So I think I will close this request.

Thanks very much for you input. This is just the way we must work with cfitsio. Let me know if you have any other suggestions or find any bugs.

-e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants