What is the purpose of "struct" and "array" modules

Matimus mccredie at gmail.com
Thu May 28 23:39:30 CEST 2009


On May 28, 11:17 am, Igor Katson <descent... at gmail.com> wrote:
> I pretty much understand what they do, but what's the case of using
> these modules by example? Is it something like pickle, to store the data
> efficiently in files?

For one it provides a mechanism for reading and writing arbitrary file
formats. For example, suppose you wanted to parse a PNG image using
python code. It is likely that that format is described in its
specification using C data structures (I've never looked at PNG format
specifically). In python you can't just read out some data and copy it
directly into a data structure. You could use the struct module
though.

It really has nothing to do with serializing python data structures.
It is (mostly) about data formats and objects defined in other
languages.

Matt



More information about the Python-list mailing list