[Tutor] revisiting struct module

shawn bright nephish at gmail.com
Fri Sep 29 03:27:32 CEST 2006


Luke !

That worked !
Man, if you knew how i have pulled my hair out over this for a while.
I did not wind up using the struct at all. I really thought that I was
supposed to, but once i made the message with ord. Like
ord(0)+ord(0)+ord(0)+ord(200)... it worked.
So i guess this means that it doesn't matter if its big endian or not ?

anyway, thanks for lots of help, i would have replied sooner, but i was
tinkering.

-sk

On 9/28/06, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
>
> shawn bright wrote:
> > Hey there,
> > I am writing this because there is something that I am not
> > understanding about the struct module.
> Okay, let's see what we can do.
> > I have to send a message over a socket. The message has to be exactly
> > 4 bytes, and the last bit has to be the value of 200.
> Okay, that makes sense.
> Except you used the term 'last bit'.  Do I understand you to mean 'the
> last part' and not 'the last bit (0/1)'?
> > so like this:
> > null,null,null,200 would be the message, and the 200 has to be an
> > unsigned long int.
> Hmm, an unsigned long int?  Isn't that 4 bytes?
> Do you  mean
> astr = chr(0)+chr(0)+chr(0)+chr(200)
> ?
> I can't really answer your specific question without this information.
> >
> > I know the stream of info that I am supposed to send the server is big
> > endian.
> > I also know that I should be using the struct.pack(), but I don't know
> > how to set this up.
> Basically, if the first 3 elements of the messages are null _characters_
> and the 200 is an unsigned long int (which is more than a 4-byte string)
> formatstr = '>cccL'
> packedstruct = struct.pack(formatstr,chr(0),chr(0),chr(0),200)
>
> Is probably how you'd do it.
> >
> > This is actually only part of the message, but I am trying to learn
> > this as i go.
> Sounds like a plan.
> HTH,
> -Luke
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060928/bfd3c573/attachment-0001.html 


More information about the Tutor mailing list