Hi

I have found myself in the following troubling situation.

I'm running the following code on a Python 2.6.5 on Linux x86:
">

(original) (raw)



On Sun, Feb 26, 2012 at 12:33, pmon mail <pmon.mail@gmail.com> wrote:
Hi

I have found myself in the following troubling situation.

I'm running the following code on a Python 2.6.5 on Linux x86:

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)�

[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct

>>> len(struct.pack('L',0))
4

Works as expected and documented (http://docs.python.org/library/struct.html).

I'm running the same code on a MacPro (OS X 10.7.3) and I'm getting the following:
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)�
\[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)\] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> len(struct.pack('L',0))
8

Documentation clearly states that the 'L' is a 4 byte integer.

Is this a bug? I'm I missing something?


By default pack uses native size, not standard size. On a 64-bit machine:

>>> struct.pack('=L', 0)
'\\x00\\x00\\x00\\x00'

>>> struct.pack('L', 0)
'\x00\x00\x00\x00\x00\x00\x00\x00'