kid wants to know more about color on the screen

Dan Bishop danb_83 at
Sat Jun 12 23:56:07 CEST 2004

"Doug Mitchell" <jmjm at> wrote in message news:<FMCyc.61975$8k4.1338501 at>...
> Dear Group,
> My son who is in grade 7 has *just* started going through the book "Python
> for the Absolute Beginner" by Michael Dawson. He and I have no programming
> experience. He is beginning this on an old win 95 computer with Python 2.2 I
> think.
> He is getting a bit frustrated with color coding.
> Later on he says that strings within quotes will be green as expected and
> then all of a sudden on the next line it will stay black :(. And when he
> does a run script there will be a syntax error as Python wont recognize this
> 'black' string but then on another occasion the 'black' will run ok :(.

It sounds like you're using a syntax highlighting text editor, that
is, it displays code in different colors depending on whether it's a
keyword, a comment, a string literal, etc.  This highlighting helps
make it easy to see syntax errors (code that's in the wrong color is a
syntax error), but it's not part of the *.py file itself, and
therefore doesn't affect the output of the program.

However, it is possible to print colored text in Python.

Under Linux, you can print "ANSI escape sequences" (Look it up on
Google) to your terminal.  These are strings starting with the control
character '\x1B' that, when printed, change the color of the text, or
move the cursor, or even change the frequency of the beep you hear
when you print '\a' (you can use this to make Python play simple

I don't know how to do it on Windows, but there might be something for
it in the msvcrt module.

More information about the Python-list mailing list