struct.pack bug?

J

Jonathan Fine

Hello

I find the following inconsistent:
===
>>> sys.version '2.4.1a0 (#2, Feb 9 2005, 12:50:04) \n[GCC 3.3.5 (Debian 1:3.3.5-8)]'
>>> pack('>B', 256) '\x00'
>>> pack('<B', 256) '\x00'
>>> pack('B', 256)
Traceback (most recent call last):
===

I was hoping that '>B' and '<B' would raise an exception,
ust as 'B' does.


On Oct 27 2006, 11:17 am, Jansson Christer reported a
different anomoly to this newsgroup, using the same
subject.
 
J

John Machin

Hello

I find the following inconsistent:
===
sys.version '2.4.1a0 (#2, Feb 9 2005, 12:50:04) \n[GCC 3.3.5 (Debian 1:3.3.5-8)]'
pack('>B', 256) '\x00'
pack('<B', 256) '\x00'
pack('B', 256)
Traceback (most recent call last):
===

I was hoping that '>B' and '<B' would raise an exception,
ust as 'B' does.

On Oct 27 2006, 11:17 am, Jansson Christer reported a
different anomoly to this newsgroup, using the same
subject.

Your Python is out-of-date in two dimensions: the 2.4 series is way
past 2.4.1, and Python 2.5 has been out for a while.

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win
32
| >>> from struct import pack
| >>> pack('<B', 256)
| __main__:1: DeprecationWarning: 'B' format requires 0 <= number <=
255
| '\x00'

Until the deprecation warning becomes an exception in 2.6, I'd suggest
doing your own checking:
assert 0 <= pack_B_candidate <= 255

HTH,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,351
Latest member
RoxiePulli

Latest Threads

Top