kid wants to know more about color on the screen

Discussion in 'Python' started by Doug Mitchell, Jun 12, 2004.

  1. 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
     
    Doug Mitchell, Jun 12, 2004
    #1
    1. Advertising

  2. Doug Mitchell

    Lee Harr Guest

    On 2004-06-12, Doug Mitchell <> 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
     
    Lee Harr, Jun 12, 2004
    #2
    1. Advertising

  3. Doug Mitchell

    Terry Reedy Guest

    "Doug Mitchell" <> wrote in message
    news:FMCyc.61975$...
    > 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
     
    Terry Reedy, Jun 12, 2004
    #3
  4. Doug Mitchell

    Dan Bishop Guest

    "Doug Mitchell" <> wrote in message news:<FMCyc.61975$>...
    > 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.
     
    Dan Bishop, Jun 12, 2004
    #4
  5. Doug Mitchell

    JanC Guest

    (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
     
    JanC, Jun 13, 2004
    #5
  6. Doug Mitchell

    Sean Berry Guest

    "Doug Mitchell" <> wrote in message
    news:FMCyc.61975$...
    > 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.
     
    Sean Berry, Jun 13, 2004
    #6
  7. Doug Mitchell

    news Guest

    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" <> wrote in message
    news:FMCyc.61975$...
    > 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
    >
    >
     
    news, Jun 14, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Brooke
    Replies:
    2
    Views:
    755
    Joe Kesselman
    Feb 12, 2006
  2. Tim Rau

    Doesn't know what it wants

    Tim Rau, Jan 26, 2008, in forum: Python
    Replies:
    11
    Views:
    521
    Tim Rau
    Jan 26, 2008
  3. dave
    Replies:
    2
    Views:
    98
    Gene Tani
    Jun 2, 2006
  4. Kamaljeet Saini
    Replies:
    0
    Views:
    480
    Kamaljeet Saini
    Feb 13, 2009
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    277
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page