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@python.org http://mail.python.org/mailman/listinfo/tutor