15 May 2012

pack/unpack


Apa maksud pack(python)


Compare to C, in Python, the data like list may not be stored as contiguous chunk of bytes.

C variable
     +-----+         +--------+
     |array|-------> |10|9|2|3|
     +-----+         +--------+
                     contiguous bytes

Python variable

     +-----+         +-------+
     |array|-------> |.|.|.|.|
     +-----+         +-------+
                      | | | |
                      | | | |
                     10 9 2 3


To handle them, it is important to convert python values to "C" structs, i.e pack them as contiguous bytes of data or dissemble a contiguous chunk of bytes to Python objects.



ref>> http://pyfunc.blogspot.com/2010/09/python-and-binary-data-part-3.html

No comments:

Post a Comment

Terima kasih