[Tutor] Oh no! Wrong advice!

Eike Welk eike.welk at gmx.net
Fri Oct 16 14:29:42 CEST 2009

Well, my ideas weren't so good:

On Friday 16 October 2009, Eike Welk wrote:
> I have an other idea for a color function. It cam be embedded in
> the print statement because it returns an empty string:
> def color(color_num):
>     '''Change text color and return empty string.'''
>     textcolor(color_num)
>     return ''
> print "There are", color(4), apples_left, \
>       color(7), "left in the basket."
This one is a bit inelegant; look at Kent's mail.
> #or
> print "There are " + color(4) + str(apples_left) \
>       + color(7) + " left in the basket."
And this statement unfortunately doesn't work. The color change 
commands are both executed when the string is assembled; before the 
string is printed. So the whole text is printed in color 7.

Sorry for wasting your time,

More information about the Tutor mailing list