1

Sorry if this might be an easy question, but I'm trying to open a Unix Executable File using Python, but it doesn't have any file extensions attached to it. The file name looks something like 'filename_bib'. I typed this and it worked:

hdulist = open('filename_bib') 

But next when I typed in hdulist.info() or hdulist.shape(), it doesn't give me anything, so I checked all its attributes and tried print(type()) and hdulist.attribute? for each attribute, but I didn't really understand any of the explanations, so I actually tried typing all of them to see what they would give me, but at some point it started giving me errors which said:

ValueError: I/O operation on closed file

so I think this may have happened when I tried using hdulist.close() or hdulist.closed(), but I don't know (1) if it was a mistake for me to try any of the attributes, (2) if it somehow changed anything from my original file, and (3) how to fix it.

I was told that this file contains bytes and that I should somehow be able to show a picture from it using Python, but this is my first time handling Unix Executable Files, and I have absolutely no idea how to start. I've handled fits and pl files before, but this is my first time trying to open something like this. I've tried looking up a bunch of things online already, but I can't find any instructions whatsoever. Please help me out if you know anything about this. I will be very grateful for any help that you could give me.

This is what it shows when I open it in Sublime: enter image description here

13
  • I don't know if it helps. On Unix, there is no such thing as extension in the sense of the m$ world. More exactly, file names can be any long and they can contain as many points as you want. And the whole thing is part of the file name. What the OS has to do with the file, it depends on its some first byte, its name is irrelevant. Commented Jul 16, 2017 at 21:15
  • Hi! Thanks for reaching out. I realized that this is a binary file, so I tried looking up details on how to open and read binary files, and so far this is what I've accomplished: Commented Jul 16, 2017 at 22:34
  • strfile = r'filename' with open(strfile,'br') as f: byte = f.read() byte_string = str(int(byte)) Commented Jul 16, 2017 at 22:35
  • (Sorry my above replies look weird. This is my first time using stack overflow, so (1) I couldn't figure out how to 'enter' to go to the next line; thus, the consecutive, separate replies) and (2) my code is not in its proper indentation) Commented Jul 16, 2017 at 22:39
  • In my code above, I'm not sure if it makes sense for me to still convert my bytes file into integer. My end goal is to somehow show an image out of this file and determine the pixel values of this image. I've been reading more information online, and I think I need to figure out the size of my file first, but I don't know how to do it yet. Would you happen to know anything on how to proceed? Commented Jul 16, 2017 at 22:44

1 Answer 1

1

As the default file access mode in python is "read only". Technically, since you have not mentioned any access mode in your command

hdulist = open('filename_bib')

file should only be for reading and nothing should have happend to the opened file.

Question: Have you tried running it in UNIX by,

./filename_bib

What was the output?

Sign up to request clarification or add additional context in comments.

6 Comments

Hi! Thanks for reaching out. I realized that this is a binary file, so I tried looking up details on how to open and read binary files, and so far this is what I've accomplished:
strfile = r'filename' with open(strfile,'br') as f: byte = f.read() byte_string = str(int(byte))
(Sorry my above replies look weird. This is my first time using stack overflow, so (1) I couldn't figure out how to 'enter' to go to the next line; thus, the consecutive, separate replies) and (2) my code is not in its proper indentation)
In my code above, I'm not sure if it makes sense for me to still convert my bytes file into integer. My end goal is to somehow show an image out of this file and determine the pixel values of this image. I've been reading more information online, and I think I need to figure out the size of my file first, but I don't know how to do it yet. Would you happen to know anything on how to proceed?
Btw, to answer your question above, I don't have prior experience with UNIX, so I don't know how to run it in UNIX.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.