0

I'm trying to change individual existing lines inside an existing tuple. Example:

for row in cursor:
     print(f'''
     
    ID: ........... {row[0]}
    Name: ......... {row[1]}
    Age: .......... {row[2]}
    Condition: .... {row[3]}
    Medicine: ..... {row[4]}
    Temperament: .. {row[5]}
    Adoptable: .... {row[6]}
    ''')

I want ID to be one color, Name, Age, Condition, Medicine, Temperament, and Adoptable to be a different color.

I can't figure out how to enter the escape codes for color inside the existing tuple. Help!

Shadow
  • 30,859
  • 10
  • 44
  • 56
Robert
  • 5
  • 2

1 Answers1

0

You need to prepend Fore.<COLOR> and preferably append Style.RESET_ALL to every element you want to style.

from colorama import Fore, Style

row = ('a', 'b')
print(f'''
ID: ........... {Fore.YELLOW + row[0] + Style.RESET_ALL}
Name: ......... {Fore.BLUE + row[1] + Style.RESET_ALL}
''')

enter image description here

DeepSpace
  • 65,330
  • 8
  • 79
  • 117
  • Doing that just produced the following error: Error while fetching data from MySQL can only concatenate str (not "int") to str – Robert Feb 01 '21 at 04:31
  • @Robert obviously if something is not a string you'll need to convert it first, ie `str(row[0])` – DeepSpace Feb 01 '21 at 08:36
  • AHHH, that's what I'd forgotten! Thanks, @DeepSpace. Row 0 is an int primary key AUTO_INCREMENT, and I didn't think I could change that before concatenation since when I did the vscode text colors changed. Very grateful! – Robert Feb 01 '21 at 20:40