0

I have a text file which looks like this. While printing the contents of file, I want to change the color of all occurences of keyword "IMPORTANT!!!" to red while printing the contents of file with python in the output console. How can I do this with python 2.7 ?

        IMPORTANT!!! abcsdfdsfs

        hello there

        IMPORTANT!!! jldsfjdkjfd
  • Change the color *where*? The answer to such a question depends heavily on what system/software/library you are using to print the contents – UnholySheep Mar 10 '22 at 11:24
  • In the output console – PRASHANT JHA Mar 10 '22 at 11:25
  • get [colorama](https://pypi.org/project/colorama/) replace `IMPORTANT!!!` with `colorama.Fore.RED + "IMPORTANT!!!" + colorama.Style.RESET_ALL` – Nullman Mar 10 '22 at 11:26
  • Can't get colorama installed, can you please suggest other way – PRASHANT JHA Mar 10 '22 at 11:29
  • 1
    if you are on linux you can do ANSI codes directly `'\033[31m' + 'IMPORTANT!!!' + '\033[39m'` on windows you need to enable it, [here](https://stackoverflow.com/a/64222858/7540911) is a good example – Nullman Mar 10 '22 at 11:32

0 Answers0