Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > kid wants to know more about color on the screen

Reply
Thread Tools

kid wants to know more about color on the screen

 
 
Doug Mitchell
Guest
Posts: n/a
 
      06-12-2004
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.
For example in Chapter 2 page 18 and 19 Mr. Dawson describes a more fancy
way of printing "Game Over" on the screen. According to *him*...

When I type the command: print "Program 'Game Over' 2.0"
print \

Instead of getting the second "print" to turn orange, like it's supposed to
when you type in a command, it just stays black. And when its time to
actually run the program, Python just prints out Program Game Over 2.0
instead of the fancy large text like that is shown in the book.

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 .

I am sure my inquiries are quite vague but I am trying to piece together
some of his 'groans and grunts' .

Any suggestions or other info you need from him?

Thanks for your advice.

Jack


 
Reply With Quote
 
 
 
 
Lee Harr
Guest
Posts: n/a
 
      06-12-2004
On 2004-06-12, Doug Mitchell <(E-Mail Removed)> wrote:
> 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.
> For example in Chapter 2 page 18 and 19 Mr. Dawson describes a more fancy
> way of printing "Game Over" on the screen. According to *him*...
>
> When I type the command: print "Program 'Game Over' 2.0"
> print \
>
> Instead of getting the second "print" to turn orange, like it's supposed to
> when you type in a command, it just stays black. And when its time to
> actually run the program, Python just prints out Program Game Over 2.0
> instead of the fancy large text like that is shown in the book.
>
> 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 .
>
> I am sure my inquiries are quite vague but I am trying to piece together
> some of his 'groans and grunts' .
>
> Any suggestions or other info you need from him?
>



It sounds like maybe you are using a "highlighting" text editor. That means
the text editor adds color depending on the syntax of the colored text.
For instance, if you have

print "Game Over"

in the editor, the word "print" might be blue because it is a python keyword
and the "Game Over" might be orange because it is a string.

It is also possible that the book is doing something similar and coloring
the different words to show more information about their purpose or meaning.

If you then run that program in the normal text terminal it would just print
out in whatever color the terminal happens to be (in my case green text on
a black background).

If you want to make the text a particular color, you would need to tell python
how to change the color, and that is going to take some more work.

You may want to join the tutor mailing list which is set up specifically to
help people who are brand new to python and/or programming.

http://mail.python.org/mailman/listinfo/tutor

 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      06-12-2004

"Doug Mitchell" <(E-Mail Removed)> wrote in message
news:FMCyc.61975$(E-Mail Removed) ...
> 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.


Congratulations to both of you.

> He is getting a bit frustrated with color coding.


This is a post-beginner subject that I think would best be skipped for now.
But I know, kids like color as much or even more than adults.

> For example in Chapter 2 page 18 and 19 Mr. Dawson describes a more fancy
> way of printing "Game Over" on the screen. According to *him*...
>
> When I type the command: print "Program 'Game Over' 2.0"
> print \
>
> Instead of getting the second "print" to turn orange, like it's supposed

to
> when you type in a command, it just stays black. And when its time to
> actually run the program, Python just prints out Program Game Over 2.0
> instead of the fancy large text like that is shown in the book.


I've have never seen the book so I can only give comments similar to
Harr's.
Standard Python by itself knows nothing of colors and fonts. The print
statement sends characters to the the file stream called stdout (for
standard output) which usually goes the the terminal and appears in
whatever font and color the terminal is set to. So Dawson had to specify
something extra to get extra control.

> 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 .


Some program editors do something extra to get different portions of the
program displayed in different colors so the programmer can pick them out m
ore easily. In the one 'he' (Dawson or your son?) used, string literals
are apparently green. String literals denoted by a ' ' pair or a " " pair
may not contain a newline (carriage return to you probably), which is to
say, cannot continue across more than one line. So, if one types:

text = "Something to display
when the monster dies"

the editor might turn 'Something to display' green, but if it knows about
Python, it will leave 'when the monster dies' black because it cannot be
part of the string on the previous line. The black rather than green says
that something is wrong, and when you try to execute the above, Python says
SyntaxError.

Terry J. Reedy




 
Reply With Quote
 
Dan Bishop
Guest
Posts: n/a
 
      06-12-2004
"Doug Mitchell" <(E-Mail Removed)> wrote in message news:<FMCyc.61975$(E-Mail Removed) m>...
> 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
music).

I don't know how to do it on Windows, but there might be something for
it in the msvcrt module.
 
Reply With Quote
 
JanC
Guest
Posts: n/a
 
      06-13-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Dan Bishop) schreef:

> Under Linux, you can print "ANSI escape sequences" [...]
> I don't know how to do it on Windows [...]


Just use an ANSI device drivers for DOS/Windows.

(try googling for "ansi.com", "ansi.sys", "nansi.com", ...)

--
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
 
Reply With Quote
 
Sean Berry
Guest
Posts: n/a
 
      06-13-2004

"Doug Mitchell" <(E-Mail Removed)> wrote in message
news:FMCyc.61975$(E-Mail Removed) ...
> 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.
> For example in Chapter 2 page 18 and 19 Mr. Dawson describes a more fancy
> way of printing "Game Over" on the screen. According to *him*...
>
> When I type the command: print "Program 'Game Over' 2.0"
> print \
>
> Instead of getting the second "print" to turn orange, like it's supposed

to
> when you type in a command, it just stays black. And when its time to
> actually run the program, Python just prints out Program Game Over 2.0
> instead of the fancy large text like that is shown in the book.
>
> 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 .
>
> I am sure my inquiries are quite vague but I am trying to piece together
> some of his 'groans and grunts' .
>
> Any suggestions or other info you need from him?
>
> Thanks for your advice.
>
> Jack
>
>




As previously mentioned... the author is not referring to the color of the
output of the code, but rather the color of the code itself.

If you are using python on a Windows machine then the way to get the text to
hightlight is to save it as a *.py file... like test.py. Without the .py at
the end the text highlighting will not work.

Once it is saved as a .py file... the following types of rules will apply.

# this entire line is red because it is a comment

"this text is green becuase it is a string in quotes"

print "Some stuff" <-- "print" is orange because it is a python keyword.

def this: <-- "this" is blue becuase it is the name of a function


I hope this helps.


 
Reply With Quote
 
news
Guest
Posts: n/a
 
      06-14-2004
Hi Doug, I am also using this text. On the whole I find it very very good.
I am looking at the pages you mention and it looks like you have not added
the rest of the code after the print \ statement ... there is a whole bunch
of code in triple quotes that follows, when this is included you should get
the correct syntax highlighting. Actually I did this exercise only last week
with 2 year 7 classes.
Your problems are common and you will soon get over them, wait till page 22
when you see escape sequences! .. realise all these things become old hat
very quickly.
regards
Darren Payne

"Doug Mitchell" <(E-Mail Removed)> wrote in message
news:FMCyc.61975$(E-Mail Removed) ...
> 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.
> For example in Chapter 2 page 18 and 19 Mr. Dawson describes a more fancy
> way of printing "Game Over" on the screen. According to *him*...
>
> When I type the command: print "Program 'Game Over' 2.0"
> print \
>
> Instead of getting the second "print" to turn orange, like it's supposed

to
> when you type in a command, it just stays black. And when its time to
> actually run the program, Python just prints out Program Game Over 2.0
> instead of the fancy large text like that is shown in the book.
>
> 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 .
>
> I am sure my inquiries are quite vague but I am trying to piece together
> some of his 'groans and grunts' .
>
> Any suggestions or other info you need from him?
>
> Thanks for your advice.
>
> Jack
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing font color from current font color to black color Kamaljeet Saini Ruby 0 02-13-2009 04:58 PM
DVD Verdict reviews: THE FRISCO KID, THE WEATHER MAN, and more! DVD Verdict DVD Video 0 02-21-2006 09:53 AM
DVD Verdict reviews: PAT GARRETT AND BILLY THE KID: SPECIAL EDITION and more! DVD Verdict DVD Video 0 01-27-2006 09:27 AM
DVD Verdict reviews: BETTER LUCK TOMORROW, A KID FOR TWO FARTHINGS, and more! DVD Verdict DVD Video 0 10-30-2003 10:04 AM
DVD Verdict reviews: THE KID STAYS IN THE PICTURE, HOMICIDE: LIFE ON THE STREET: THE COMPLETE SEASONS 1 AND 2, and more! DVD Verdict DVD Video 0 08-04-2003 09:05 AM



Advertisments