Re: [Tutor] Understanding what the code does behind the scenes

2009-10-16 Thread Alan Gauld
"Dave Angel" wrote for text, color in color_items: #3 textcolor(color) #4 print text#5 Ah! Good call, I never thought of unpacking the tuple in the loop. Big improvement. It would be possible (and maybe even desirable) to write a differe

Re: [Tutor] Understanding what the code does behind the scenes

2009-10-16 Thread Alan Gauld
"Katt" wrote def colorPrint(strings): for string in strings: textcolor(string[1]) print string[0], In the above function please let me know if I am correct in my interpretation. The first line of course would be the defining of the function and puting something in the

Re: [Tutor] Understanding what the code does behind the scenes

2009-10-16 Thread Kent Johnson
On Fri, Oct 16, 2009 at 7:21 AM, Dave Angel wrote: > My attempt at readability  (untested): > > def colorPrint(color_items):       #1 >   """Call this function to print one or more strings, each with >       a color number specified, to the console.  The argument >       is a list of items, where

Re: [Tutor] Understanding what the code does behind the scenes

2009-10-16 Thread Kent Johnson
On Fri, Oct 16, 2009 at 7:53 AM, 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 ''

Re: [Tutor] Understanding what the code does behind the scenes

2009-10-16 Thread Eike Welk
On Friday 16 October 2009, Katt wrote: > > print "There are", > > textcolor(4) > > print apples_left, > > textcolor(7) > > 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. I think

Re: [Tutor] Understanding what the code does behind the scenes

2009-10-16 Thread Dave Angel
Katt wrote: 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", textcolor(4) print apples_left, textcolor(7) pri

Re: [Tutor] Understanding what the code does behind the scenes

2009-10-16 Thread Katt
Message: 3 Date: Thu, 15 Oct 2009 08:11:11 +0100 From: "Alan Gauld" To: tutor@python.org Subject: Re: [Tutor] Changing the color of text in the windows shell (WinXP/python 2.6.2) Message-ID: Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response The textcolor() func