Question about Reading Files

genxtech jrmy.lnrd at gmail.com
Sat Sep 4 20:07:01 EDT 2010


On Sep 4, 7:23 pm, Mats Rauhala <mats.rauh... at gmail.com> wrote:
> On 2010-09-04, genxtech <jrmy.l... at gmail.com> wrote:
>
> > 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.



More information about the Python-list mailing list