<div dir="ltr"><br><br><div class="gmail_quote">On Sun, Feb 26, 2012 at 12:33, pmon mail <span dir="ltr"><<a href="mailto:pmon.mail@gmail.com">pmon.mail@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Hi<div><br></div><div>I have found myself in the following troubling situation.</div><div><br></div><div>I'm running the following code on a Python 2.6.5 on Linux x86:</div><div><div><font face="'courier new', monospace"><div>
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) </div><div>[GCC 4.4.3] on linux2</div><div>Type "help", "copyright", "credits" or "license" for more information.</div><div>>>> import struct</div>
<div>>>> len(struct.pack('L',0))</div><div>4</div></font></div></div><div><br></div><div>Works as expected and documented (<a href="http://docs.python.org/library/struct.html" target="_blank">http://docs.python.org/library/struct.html</a>).</div>
<div><br></div><div>I'm running the same code on a MacPro (OS X 10.7.3) and I'm getting the following:</div><div><div><font face="'courier new', monospace">Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) </font></div>
<div><font face="'courier new', monospace">[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin</font></div><div><font face="'courier new', monospace">Type "help", "copyright", "credits" or "license" for more information.</font></div>
<div><font face="'courier new', monospace">>>> import struct</font></div><div><font face="'courier new', monospace">>>> len(struct.pack('L',0))</font></div>
<div><font color="#ff0000" face="'courier new', monospace">8</font></div></div><div><br></div><div>Documentation clearly states that the 'L' is a 4 byte integer.</div><div><br></div>
<div>Is this a bug? I'm I missing something?</div><br></div></blockquote></div><br>By default pack uses native size, not standard size. On a 64-bit machine:<br><br>>>> struct.pack('=L', 0)<br>'\x00\x00\x00\x00'<br>
>>> struct.pack('L', 0)<br>'\x00\x00\x00\x00\x00\x00\x00\x00'<br><br><br><br></div>