Reading binary data

Fredrik Lundh fredrik at pythonware.com
Wed Nov 23 13:20:43 EST 2005


David M wrote:

> OK so here is my task.  I want to get at the data stored in
> /var/account/pacct, which stores process accounting data, so that I can
> make it into a more human understandable format then what the program
> sa can do.  The thing is, its in a binary format and an example program
> that reads some data from the file is done in C using a struct defined
> in sys/acct.h.
>
> http://www.linuxjournal.com/articles/lj/0104/6144/6144l2.html
>
> So I was wondering how can I do the same thing, but in python?  I'm
> still learning so please be gentle.

outline:

1. load the data

    f = open(filename, "rb")

    data = f.read()

2. parse it:

    http://docs.python.org/lib/module-struct.html

</F> 






More information about the Python-list mailing list