Question about Reading Files

G

genxtech

Hello. I am still really new to python and I have a project where I
am trying to use the data files from another program and write a new
program with new user interface and all. My first step was to open
one of the files in 'rb' mode and print the contents, but I am
unfamiliar with the format. Here is what was printed to the terminal:

b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f
\x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y
\x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$
\x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n
\x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc
\x00\x00\x0c\x19\x00\x00'

I am using Python 3.1 on a Fedora 13 box if that makes any difference.
Any advise on how to decode the data would be greatly appreciated.
 
M

Mats Rauhala

Hello. I am still really new to python and I have a project where I
am trying to use the data files from another program and write a new
program with new user interface and all. My first step was to open
one of the files in 'rb' mode and print the contents, but I am
unfamiliar with the format. Here is what was printed to the terminal:

I am using Python 3.1 on a Fedora 13 box if that makes any difference.
Any advise on how to decode the data would be greatly appreciated.

It's difficult to elaborate with only that information. What you have
done now is opened a file in read binary mode (r = read, b = binary) and
then tried to print it. Python has escaped the data as hex (\x01) and is
basically a hex dump of the data file.

For decoding the data, you either need to somehow figure out the format
of the data and then decode it accordingly. If you're on unix box the
'file' command might be of help.

If you're not on a unix box, you could check out how the file command
tries to find the type of the file. The man page for magic [1] could be
of help. Also see list of magic numbers [2]

[1] http://linux.die.net/man/5/magic
[2] http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html
 
M

MRAB

Hello. I am still really new to python and I have a project where I
am trying to use the data files from another program and write a new
program with new user interface and all. My first step was to open
one of the files in 'rb' mode and print the contents, but I am
unfamiliar with the format. Here is what was printed to the terminal:

b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f
\x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y
\x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$
\x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n
\x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc
\x00\x00\x0c\x19\x00\x00'

I am using Python 3.1 on a Fedora 13 box if that makes any difference.
Any advise on how to decode the data would be greatly appreciated.

I googled and found this:

http://stackoverflow.com/questions/2754751/what-file-format-contents-starts-with-ures

which suggests "Universal Resource Editor (URE) that comes with the
OS/2 Toolkit".
 
G

genxtech

Hello.  I am still really new to python and I have a project where I
am trying to use the data files from another program and write a new
program with new user interface and all.  My first step was to open
one of the files in 'rb' mode and print the contents, but I am
unfamiliar with the format.  Here is what was printed to the terminal:
I am using Python 3.1 on a Fedora 13 box if that makes any difference.
Any advise on how to decode the data would be greatly appreciated.

It's difficult to elaborate with only that information. What you have
done now is opened a file in read binary mode (r = read, b = binary) and
then tried to print it. Python has escaped the data as hex (\x01) and is
basically a hex dump of the data file.

For decoding the data, you either need to somehow figure out the format
of the data and then decode it accordingly. If you're on unix box the
'file' command might be of help.

If you're not on a unix box, you could check out how the file command
tries to find the type of the file. The man page for magic [1] could be
of help. Also see list of magic numbers [2]

[1]http://linux.die.net/man/5/magic
[2]http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html

I am using Fedora 13. When I run the file command the response is
that it is a 'data' file. If there are any tips on how to
programatically figure out the format, I would greatly appreciate it.
 
P

Peter Otten

genxtech said:
Hello. I am still really new to python and I have a project where I
am trying to use the data files from another program and write a new
program with new user interface and all. My first step was to open
one of the files in 'rb' mode and print the contents, but I am
unfamiliar with the format. Here is what was printed to the terminal:

b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f
\x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y
\x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$
\x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n
\x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc
\x00\x00\x0c\x19\x00\x00'

I am using Python 3.1 on a Fedora 13 box if that makes any difference.
Any advise on how to decode the data would be greatly appreciated.

What's the name of the file?
What's the program that uses the file?
If the source code is available, what library does that program use to read
the file?

Peter
 
M

Mats Rauhala

I am using Fedora 13. When I run the file command the response is
that it is a 'data' file. If there are any tips on how to
programatically figure out the format, I would greatly appreciate it.

I tried python-magic from the fedora repositories, but was unable to get
it working. However there was another project at github [1] which seems
to be working, at least with python 2.6. An easy way to test whether it
works is by unpacking it, going to the directory, opening the
interactive shell and running 'import magic' and
'magic.from_file("testdata/test.pdf")'

See help(magic) for more help

[1] http://github.com/ahupp/python-magic
 
G

genxtech

What's the name of the file?
What's the program that uses the file?
If the source code is available, what library does that program use to read
the file?

Peter

Unfortunately the source code isn't available, so I'm trying to figure
out a way to get the format of the file on my own.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top