Strange extra f added to bytes object
Ned Batchelder
ned at nedbatchelder.com
Sun Oct 6 20:39:39 EDT 2013
On 10/6/13 6:47 PM, Robert Jackson wrote:
> I am very new to python so I'll apologize up front if this is some
> boneheaded thing. I am using python and pyserial to talk to an
> embedded pic processor in a piece of scientific equipment. I
> sometimes find the when I construct the bytes object to write it adds
> an extra f to the first byte.
>
> For example if I have b'\x03\x66\x02\x01\xaa\xbb' it evaluates
> to b'\x03f\x02\x01\xaa\xbb', which doesn't even seem valid.
>
> Can anyone shine some light this?
>
>
b'\x66' == b'f' . The hex for "f" is 66. The f isn't inserted, it's
the second byte of your string. When Python displays a string, is uses
the ASCII character if it can, and a hex escape if it can't. When you
use a hex value that is a valid ASCII character, it will display the
character.
--Ned.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20131006/6275fb7a/attachment.html>
More information about the Python-list
mailing list