[Python-talk] struct pack
Bruce Labitt
bruce.labitt at myfairpoint.net
Thu Aug 27 19:30:40 EDT 2009
Lloyd Kvam wrote:
> On Thu, 2009-08-27 at 12:01 -0400, bruce.labitt at autoliv.com wrote:
>
>> I did not understand the Section 8.3.1 Struct Objects.
>> http://docs.python.org/library/struct.html
>>
>> Can someone provide a simple example (somewhat like above) that uses
>> struct objects?
>>
>>
> In [13]: from struct import Struct
>
> In [14]: s = Struct(fmt)
>
> In [15]: apackt = s.pack( *anum)
>
> In [16]: apack = array( apackt)
>
> Essentially the fmt is compiled once and reused with subsequent calls to
> the Struct.pack method.
>
>
Thanks again! Very helpful.
-Bruce
More information about the Python-talk
mailing list