[Tutor] Understanding what the code does behind the scenes
the_only_katala at verizon.net
Fri Oct 16 11:03:40 CEST 2009
> Message: 3
> Date: Thu, 15 Oct 2009 08:11:11 +0100
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> To: tutor at python.org
> Subject: Re: [Tutor] Changing the color of text in the windows shell
> (WinXP/python 2.6.2)
> Message-ID: <hb6huh$cba$1 at ger.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> The textcolor() function returns None. so you need to keep it
> out of your print statement:. This means you need to split your
> print into multiple separate statements. (This will also be true
> for the pywin32 version)
> print "There are",
> print apples_left,
> print "left in the basket."
The above code is very easy to understand when looking at it, but from what
I see of other programmers this would not be as pythonic.
> The way I'd handle thus is to create a function which takes a
> list of tuples as input, with each tuple containing the string
> and its colour:
> def colorPrint(strings):
> for string in strings:
> print string,
In the above function please let me know if I am correct in my
The first line of course would be the defining of the function and puting
something in the parenthesis indicates that you will be passing a value to
The second line says that for each string in the colorPrint statement check
to see what the color code is.
The third line says that if it detects a ",#" to change it to a color based
on the textcolor function in the WConio module.
The fourth line puzzles me though. I think it says that when the textcolor
returns the zero that it doesn't print the None? I am not sure though.
Could you let me know if I have the right idea?
Thanks in advance,
More information about the Tutor