[Tutor] pack function

Lloyd Kvam pythontutor at venix.com
Sat Oct 4 14:25:05 EDT 2003


(pack is actually in the struct module.)
This module allows you to manipulate binary data structures that typically
map to C structs, hence the name.  The binary structure for things like
integers will vary based upon the processor and system architecture.

On an Intel X86 processor the bytes that make up an integer are stored with
the least significant byte first (little endian) while many other processors
would store the most significant byte first (big endian).  This is very much
analogous to languages that read right-to-left versus left-to-right.

I've used struct to handle things like dBase files that have header information
that was (presumably) written from a C struct and specifies things like
record size, number of fields, and field names.

You need to know the specs for your target to know the right thing to do.  If
your target is a C program on the same kind of system, then Native, which is
the default, should generally do the right thing.  "Python in a Nutshell" has
a good description of struct, but it is not so very different from the module
documentation.

Jimmy verma wrote:

> Hello,
> 
> Can someone please give me some idea about the pack module. I have tried 
> to read it from the documentation. But not clear about it.
> Statements like pack('>L',0)
> 
> Where > indicates the endienness.
> 
> I will highly appriciate any kind of suggestion regarding pack.
> 
> Thanks in advance.
> 
> Regards,
> 
> James
> 
> _________________________________________________________________
> Three simple steps. They guarantee your safety. 
> http://server1.msn.co.in/features/general/SMBvirus/index.asp Protect 
> yourself against the SMB.EXE virus.
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582




More information about the Tutor mailing list