467,161 Members | 848 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

Is this a bug of module struct?

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,'0123456789ab cd',6)
'\x01\x00\x00\x00%\x910\x01\x0e\x00\x00\x000123456 789abcd\x00\x00\x06\x00\x00\x00'
>>struct.pack('3I14s',1,19960101,14,'0123456789abc d')+struct.pack('I',6)
'\x01\x00\x00\x00%\x910\x01\x0e\x00\x00\x000123456 789abcd\x06\x00\x00\x00'

Aug 25 '06 #1
  • viewed: 1508
Share:
2 Replies
I got it, alignment issue...
>struct.pack('!3I14sI',1,19960101,14,'0123456789ab cd',6)
'\x01\x00\x00\x00%\x910\x01\x0e\x00\x00\x000123456 789abcd\x06\x00\x00\x00'
>struct.pack('!3I14s',1,19960101,14,'0123456789abc d')+struct.pack('!I',6)
'\x01\x00\x00\x00%\x910\x01\x0e\x00\x00\x000123456 789abcd\x06\x00\x00\x00'
rong.x...@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,'0123456789abc d',6)
'\x01\x00\x00\x00%\x910\x01\x0e\x00\x00\x000123456 789abcd\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\x000123456 789abcd\x06\x00\x00\x00'
Aug 25 '06 #2
On 2006-08-25, ro*******@gmail.com <ro*******@gmail.comwrote:
Before I was bitten by the difference below, I think these two
ways are the same. However, they are not.
As is explained here:

http://www.python.org/doc/current/li...le-struct.html

Is there any geek who can tell me if this is a bug?
Yes there is.

No it isn't a bug.

It's all explained in the manual: If you don't specify a byte
order, native byte order an alignment are assumed.

--
Grant Edwards grante Yow! NEWARK has been
at REZONED!! DES MOINES has
visi.com been REZONED!!
Aug 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Gordon Scott | last post: by
2 posts views Thread by Angelo Secchi | last post: by
reply views Thread by Josiah Carlson | last post: by
6 posts views Thread by chris | last post: by
4 posts views Thread by ahn1@llnl.gov | last post: by
reply views Thread by Jérôme Le Bougeant | last post: by
reply views Thread by Keith | last post: by
40 posts views Thread by rjcarr | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.