Convert variable directly into a string (no ASCII)

Stephen Hansen apt.shansen at gmail.com
Sat May 2 20:24:15 CEST 2009


> I need to print variables out over serial, however I need them to not be
> in ASCII, ie if the variable is 5 then print 5 not "5".
>
> The function that writes to the serial port requires a string and I can
> send non-variables out with the string "/x05" for 5.
>
> Is this even possible?
>

Check out the struct module.

>>> a = 5
>>> struct.pack("b", a)
'\x05'

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090502/03035786/attachment.html>


More information about the Python-list mailing list