[Tutor] how to read over serial port

shawn bright nephish at gmail.com
Mon Nov 3 22:08:56 CET 2008


yes, they look like this
����������������������

so i used your print repr(chr(ord(i))) and got this
'\x00'
'\x06'
'\x00'
':'
'\x80'
'\x1f'
'\x16'
'g'
'J'
's'
'\xde'
'\xc0'
'J'
's'
'\xde'
'\xc0'
'\xce'
'\xcc'
'\x06'
'\n'
'\x00'
'\x00'
' '
'\xaf'
'J'
's'
'\xde'
'\xc0'

so, what do i do now?
and thanks for the info, by the way, been writing python for 2 years,
but this is all new to me.

shawn



On Mon, Nov 3, 2008 at 11:28 AM, Lie Ryan <lie.1296 at gmail.com> wrote:
> On Mon, 03 Nov 2008 08:48:44 -0600, shawn bright wrote:
>
>> ok, i have another question:
>> if i run this:
>> #!/usr/bin/env python
>> f = 'test_out'
>> f = open(f, 'r').read()
>> for i in f:
>>     print ord(i)
>>
>> I get this:
>> 0
>> 6
>> 0
>> 58
>> 128
>> 31
>> 22
>> 103
>> 74
>> 115
>> 222
>> 192
>> 74
>> 115
>> 222
>> 192  (deleted some in the email for brevity)
>>
>> if i do
>> for i in f:
>>     print chr(ord(i))
>> i get the same weird characters.
>> should these be read some other way?
>
> Wait... are these "weird" characters in the form of:
> ����������������������
>
> or if you used "print repr(chr(ord(i)))": "\x87\x88\x89\x8a\x8b\x8c\x8d
> \x8e\x8f\x90\x91"
>
> That is python's escape characters. Python's default byte-to-character
> encoding is ASCII, a 7-bit encoding, values in the range(128, 256) cannot
> be represented in ASCII so python uses � to represent these
> unrepresentable characters. If you used repr(), it would escape the
> unrepresentable characters into an escaped form, using '\xkk' where kk is
> the two-digit hexadecimal representing the byte value of the character
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list