Skip to content
Advertisement

How do I use colorama inside a tuple?

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!

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement