python - Changing text font and colour -


whether it's module or can define in code, there way change output text making italic or bold? also, colours thing?

taking question @lukek posted, can use ansi escape sequences anywhere in strings:

print("roses \033[31mred\033[0m") # make red... red 

you can combine them in way (i hope it's clear enough):

bold_and_red = "\033[1;31m" 

on other hand, can find modules allow simpler (or nicer) ways of doing it, prefer writing code minimal dependencies, put global variables , later concatenate them strings:

red    = "\033[31m" bold   = "\033[1m" italic = "\033[3m" reset  = "\033[0m"  print(bold + red + "error: " + reset + italic + "blah blah...") 

last note! escape sequences work in terminals, , don't think work in windows cmd.


Comments