Nice mention of the struct module, Alan. I had forgotten about it and I just finished an app that really could've been simplified by it. I might retool it to use struct when I have to revisit it for the next part of my class assignment.
On Tue, Oct 21, 2008 at 3:34 PM, shawn bright <[EMAIL PROTECTED]> wrote: > Thanks for all your help on this, gents. > found what works. > shawn > > On Mon, Oct 20, 2008 at 6:06 PM, Alan Gauld <[EMAIL PROTECTED]> > wrote: >> >> "shawn bright" <[EMAIL PROTECTED]> wrote >> >>> i have a script that needs to send a number as two bytes. >>> how would i be able to see a number expressed as a hi byte and a lo byte? >> >> One way is to use the struct module. >> It has the advantage of allowing selection of big endian(>) or little >> endian(<) representation etc. The H symbol can be used for a short >> integer - ie 2 bytes... >> >> eg >> >>>>> import struct >>>>> b = struct.pack(">H", 279) >>>>> b >> >> '\x01\x17' >>>>> >>>>> b = struct.pack("<H", 279) >>>>> b >> >> '\x17\x01' >>>>> >> >> Note that Python will print bytes with printable representations as >> the character form but the data is still two bytes. >> >> eg >>>>> >>>>> struct.pack("H", 33) >> >> '!\x00' >>>>> >>>>> chr(33) >> >> '!' >> >> >> HTH, >> >> -- >> Alan Gauld >> Author of the Learn to Program web site >> http://www.freenetpages.co.uk/hp/alan.gauld >> >> >> >> _______________________________________________ >> Tutor maillist - Tutor@python.org >> http://mail.python.org/mailman/listinfo/tutor > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor