[Tutor] question about a number and bytes.

Michael Langford michael.langford at rowdylabs.com
Tue Jan 29 22:16:12 CET 2008


Use pyserial:

http://pyserial.sourceforge.net/

Use struct.pack:

http://docs.python.org/lib/module-struct.html

The format string will depend whether you need little or big endian.

       --Michael


On Jan 29, 2008 4:13 PM, shawn bright <nephish at gmail.com> wrote:
> Thanks for your reply.
> i need to do this in python because python is what scripting language
> our data I/O system is written in.
> i am writing a command out over a serial port that tells an RTU to
> change part of it's program. I am not sure what you mean by using it
> in any other python context, this is about the only thing we will need
> to be able to do this for, at least, that is the case for right now.
> thanks
> sk
>
>
> On Jan 29, 2008 2:55 PM, Tiger12506 <keridee at jayco.net> wrote:
> > > Hello there all.
> > >
> > > I have a need to make a hi byte and lo byte out of a number.
> > >
> > > so, lets say i have a number 300, and need this number to be
> > > represented in two bytes, how do i go about that?
> >
> > First question. Why would you need to do this in python? Second question. If
> > you could do that, how would you use it in any other python context?
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com


More information about the Tutor mailing list