[Tutor] [tutor] how to cast to stucture

Pawel Kraszewski Python at kraszewscy.net
Tue Sep 5 09:34:39 CEST 2006


Dnia wtorek, 5 września 2006 08:32, emilia12 at mail.bg napisał:

> i have a complex data in binary file and i want to read its
> fields... the C way is to read file in buffer and then cast
> it to proper structure. Is there a way to do the same in
> Python or i have to read the data byte by byte ?

cite:

-----------------
struct -- Interpret strings as packed binary data 
 
 
 This module performs conversions between Python values and C structs 
represented as Python strings. It uses format strings (explained below) as 
compact descriptions of the lay-out of the C structs and the intended 
conversion to/from Python values. This can be used in handling binary data 
stored in files or from network connections, among other sources.
-----------------


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

-- 
 Pawel Kraszewski
 http://www.kraszewscy.net


More information about the Tutor mailing list