is there a problem on this simple code

Bengt Richter bokr at oz.net
Sun Mar 13 07:40:20 CET 2005


On 12 Mar 2005 20:12:19 -0800, "John Machin" <sjmachin at lexicon.net> wrote:

>
>Bengt Richter wrote:
>> On 12 Mar 2005 17:35:50 -0800, "John Machin" <sjmachin at lexicon.net>
>wrote:
>>
>> >
>> >mensanator at aol.com wrote:
>> >>
>> >> What actually gets transmitted is "C\x01\x02\x10'\x83".
>> >
>> >No, that's repr(What actually gets transmitted)
>>
>> If so, that's 6 bytes, not 18:
>>
>>  >>> "C\x01\x02\x10'\x83"
>>  "C\x01\x02\x10'\x83"
>>  >>> list("C\x01\x02\x10'\x83")
>>  ['C', '\x01', '\x02', '\x10', "'", '\x83']
>>  >>> len("C\x01\x02\x10'\x83")
>>  6
>>
>> OTOH,
>>  >>> list(r"C\x01\x02\x10'\x83")
>>  ['C', '\\', 'x', '0', '1', '\\', 'x', '0', '2', '\\', 'x', '1', '0',
>"'", '\\', 'x', '8', '3']
>>  >>> len(r"C\x01\x02\x10'\x83")
>>  18
>>
>> >
>> >> That's 18 bytes. Is the command supposed to be the ASCII
>> >> characters \x01 or a single byte whose value is 1?
>> >
>> >For a start, according to the OP's code, the command ('C' a.k.a. 67)
>is
>> >first. The 1 is a meant to be a message number.
>> >
>> >Secondly, the hardware smells like it's got an 8080 or 6502 inside.
>The
>> >likelihood that it groks Python/C string representation is minimal.
>> >Folk just don't send 18 bytes at 9600 bps when 6 bytes will do.
>> >
>>
>> Regards,
>> Bengt Richter
>
>The number of bytes transmitted is 6. However the length of the visual
>representation of what was sent is 18. Mensator was confused by this,
>as was apparent from his/her question "Is the command supposed to be
>the ASCII characters \x01 or a single byte whose value is 1?". I tried
>to explain this to him/her. However it's not apparent whether your post
>is part of the problem or part of the solution. Enlightenment, please.
>

Sorry for jumping in with a largely irrelevant comment. I didn't look
at the code, just sought to illustrate the 6/18 thing further, in a kneejerk reaction.
Though BTW FWIW the visual sequence of glyphs representing the data was more a str output
than repr, I guess:

 >>> repr("C\x01\x02\x10'\x83")
 '"C\\x01\\x02\\x10\'\\x83"'
 >>> str("C\x01\x02\x10'\x83")
 "C\x01\x02\x10'\x83"

Sorry, no enlightenment ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list