[Tutor] character format
jfouhy@paradise.net.nz
jfouhy at paradise.net.nz
Thu May 12 02:50:28 CEST 2005
Quoting "D. Hartley" <denise.hartley at gmail.com>:
> Does anyone have a hint as to what things like this:
> \xaf\x82\r\x00\x00\x01\
>
> refer to?
Basically, they are unprintable characters.
>>> ord('\x82')
130
>>> chr(130)
'\x82'
If you look at http://asciitable.com/, you will see that ascii chracter 130 is
an e with a tick on its head. This is not something you can find on your
keyboard, so python can't/won't display it.
Also, if you do some maths, you will see that 82 in hexadecimal is 130 in decimal:
>>> 8*16 + 2
130
So that explains why it is x82 :-) (with the backslash to indicate an escape
sequence, and an x to indicate hexadecimal)
'\r' is the carriage return character [1]. Looking at asciitable.com, I can see
that it is hex d / ascii 13.
>>> '\x0d' == '\r'
True
Hope this helps!
--
John.
[1] Historical note: In the days of typewriters [2], a carriage return would
send the carriage (with the ink in it) back to the left, so you could start
typing a new line. A line feed would advance the paper by one line. These were
separate operations 'cause sometimes you wouldn't want to do both.
The characters entered ASCII (because of early printers?) and different
operating systems used them to end lines in different ways: in UNIX, the
end-of-line character is a newline character ('\n'); in MSDOS/Windows it is both
('\r\n'); and I think Macintoshes just use a '\r'.
Fortunately, python has so-called "universal newline" support, so you don't need
to worry about all that :-)
[2] Before my time, so there could be errors of fact...
More information about the Tutor
mailing list