Is this a bug of module struct?

rong.xian at gmail.com rong.xian at gmail.com
Fri Aug 25 05:53:59 EDT 2006


I got it, alignment issue...
> >>> struct.pack('!3I14sI',1,19960101,14,'0123456789abcd',6)
> '\x01\x00\x00\x00%\x910\x01\x0e\x00\x00\x000123456789abcd\x06\x00\x00\x00'
> >>> struct.pack('!3I14s',1,19960101,14,'0123456789abcd')+struct.pack('!I',6)
> '\x01\x00\x00\x00%\x910\x01\x0e\x00\x00\x000123456789abcd\x06\x00\x00\x00'

rong.x... at gmail.com wrote:
> Before I was bitten by the difference below, I think these two ways are
> the same.
> However, they are not.
> Is there any geek who can tell me if this is a bug?
> (some weird '\x00\x00' was inserted between '0123456789abcd' and 6 )
>
>
> >>> struct.pack('3I14sI',1,19960101,14,'0123456789abcd',6)
> '\x01\x00\x00\x00%\x910\x01\x0e\x00\x00\x000123456789abcd\x00\x00\x06\x00\x00\x00'
> >>> struct.pack('3I14s',1,19960101,14,'0123456789abcd')+struct.pack('I',6)
> '\x01\x00\x00\x00%\x910\x01\x0e\x00\x00\x000123456789abcd\x06\x00\x00\x00'




More information about the Python-list mailing list