[Tutor] ASCII Code

Glen Wheeler wheelege@tsn.cc
Mon, 28 May 2001 22:01:36 +1000


  Seems no reply yet...I'll throw in my two cents although be certain I am
far from being confident in python :)

> I'm just a little curious about something I find odd in Python.  Here
> are two scripts that do pretty much the same thing...
>
 > <snip>
>
> Both scripts have the same output.  But, if in the first script you look
> at chars, you don't see the same characters that are printed.  Instead,
> you see the normal 'keyboard' letters and then the (octal) code '\177',
> '200', etc. for all the special characters.  Obviously Python can
> display those other characters, it did when I printed them.
>

  You must be in a pre-2.1 python - the octal representation was thrown out
for hex in 2.1, it was never meant to be octal.  I myself have 2.0 so I
can't test this, but I seem to recall it in the list of changes in the
readme for 2.1.

> And, why does Python choose to display the special characters in octal?

  Well, it chooses hex because hex is really easy for computers (and humans)
to convert to binary - which as well all know is what computers think in.
Octal is easy to use as a midpoint type stage...so I guess that is why it
has been sneaking in for so long.  But maybe not - someone correct me?

> This makes it slightly confusing to me.  For example, ord('\n'), the
> carriage return, gives me 10, but if I print '\010', what I really mean
> is print '\012'.

  Right, don't think you will ever use escape codes in decimal...it just
isn't going to happen :)

>  Again, these are things that I find odd, and things I
> have to try and remember when I am coding.  Of course, I don't actually
> use these commands very often in coding...
>

  No prob,
  Glen.

>  - Tim
>