A little comments of ctypes and construct.
一首诗
newptcai at gmail.com
Fri Nov 21 08:41:04 EST 2008
OK, I was wrong with construct!
I wrote to the author and he replied. It works!
I am really glad there IS a easy way to handle binary data in python.
>>> from construct import *
>>>
>>>
>>> point = Struct("point",
... SNInt32("x"), # Signed, Native byte-order, Int 32 bits
('int' is platform specific, so your int may be different)
... SNInt32("y"),
... )
>>>
>>> shape = Struct("shape",
... SNInt32("z"),
... Rename("ap", # without the Rename field, the name would be
"point" (Arrays inherit their name from their element)
... Array(2, point)
... ),
... )
>>>
>>> c = shape.parse("zzzzxxxxyyyyXXXXYYYY")
>>> print c
Container:
z = 2054847098
ap = [
Container:
x = 2021161080
y = 2038004089
Container:
x = 1482184792
y = 1499027801
]
>>>
More information about the Python-list
mailing list