On Sun, Jul 27, 2008 at 7:17 PM, Larry Bates <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: >> On Sun, Jul 27, 2008 at 7:01 PM, Larry Bates <[EMAIL PROTECTED]> >> wrote: >>> [EMAIL PROTECTED] wrote: >>>> i want to send unsigned 32 bit integer to socket, and looking for >>>> something equivalent to this method... >>>> >>>> http://livedocs.adobe.com/flex/2/langref/flash/net/Socket.html#writeUnsignedInt() >>>> >>>> is there such method / library available in python?! >>> >>> You will need to use struct module to build the 4 byte value and then >>> send >>> it. >>> >>> Something like (not tested): >>> >>> import struct >>> us32bit = struct.pack("I", value) >>> s.send(us32bit) >> >> thanks a lot!!! >> >> just to make sure if I want 32 bit or 4 bytes then should I use the >> short or integer or long? >> >> this is short >>>>> >>>>> struct.pack('!h',3) >> >> '\x00\x03' >> >> this is integer >>>>> >>>>> struct.pack('!i',3) >> >> '\x00\x00\x00\x03' >> >> this is long >>>>> >>>>> struct.pack('!l',3) >> >> '\x00\x00\x00\x03' > > Short is 16 bits, Integer is 32 bits, long is 64 bits (as I read and have > found). thanks a lot!!! re-read it again!!!
from the struct doc! Standard size and alignment are as follows: no alignment is required for any type (so you have to use pad bytes); short is 2 bytes; int and long are 4 bytes; long long (__int64 on Windows) is 8 bytes; float and double are 32-bit and 64-bit IEEE floating point numbers, respectively. -- http://mail.python.org/mailman/listinfo/python-list