Dynamic text color

John Posner jjposner at optimum.net
Tue Jan 5 15:34:14 EST 2010


On Tue, 05 Jan 2010 15:08:04 -0500, Dave McCormick <mackrackit at gmail.com>  
wrote:

>>
>> It's certainly a mistake to use the expression "str(rList).split()".  
>> Using str() to convert the list "rList" into a string creates a mess  
>> that includes square-bracket characters. Did this actually work for you?

> It sort of worked.  With one color file it seemed fine but after I  
> posted I added another color file and things fell apart.
> Now with the above fixes it works with three colors from three files.   
> When the list are printed to the shell the list look like this:
> redList ['red', 'dog', 'apple', '#']
> blueList ['blue', 'ball', 'berry']
> greenList ['green', 'grass', 'do']
>
> But another problem is noticed.  It does not matter if the list is built  
> in code or from a file.
> If dog is entered, "do" will be green with the "g" being red.  Back to  
> the drawing board.....

It sounds like the program is doing exactly what you TOLD it to do (which  
might not be what you WANT it to do):

  1. In an earlier pass on the text, color the string "dog" red.
  2. In a later pass, color the string "do" green.

You need to decide what you WANT to happen if one word to be colored is a  
substring of another word to be colored differently. Or maybe you want to  
outlaw such situations. After making that decision, you can start to think  
about how to write the appropriate code.

Best,
John



More information about the Python-list mailing list