Search word in python
Question: I have text file, I am searching for specific word "Belief". I want the word
to be shown in red colour if it was found.

    
    
    searchfile = open("demo.txt", "r")
    text=input("Enter search word :")
    for line in searchfile:
        if text in line:
            print(line)
    searchfile.close()
    


Answer: You can get colors as shown
[here](http://stackoverflow.com/questions/287871/print-in-terminal-with-
colors-using-python)

If you are not using Windows you could try `termcolor` to do something like
this:

    
    
    from termcolor import colored
    
    text=input("Enter search word :")
    with open("demo.txt", "r") as searchfile:
        for line in searchfile:
            if text in line:
                print(colored(text,'red').join(line.split(text)))
    

Example:

    
    
    s = "123 321 123 321 123"
    print(colored("321",'red').join(s.split("321")))
    

With output: [![enter image description
here](http://i.stack.imgur.com/McqsP.png)](http://i.stack.imgur.com/McqsP.png)

If you do use windows, you could still run the same code as above, as long as
you add the following two lines at the beginning of your script:

    
    
    from colorama import init
    init()
    

Both libraries are pip-installable and lightweight.

