On Dec 4, 3:33 pm, Thomas Heller <[EMAIL PROTECTED]> wrote:

> Roy Smith schrieb:
>
> > I'm working with marshaling data over a binary wire protocol.  I'm
> > using struct.pack() to handle the low-level encoding of ints.  One of
> > the things I need to do is make sure an int can be represented in 4
> > bytes.

> You could try something like this:
>
> import ctypes
> def int_fits_in_32bit(value):  
>   return ctypes.c_int32(value) == value

Good idea!  It turns out you've got to do types.c_int32(value).value()
== value, but that does indeed seem to do exactly what I want.
Thanks.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to