how to make a phrase in python that is input by a user not case
Question: I am trying to fix my code so when the user enters a phrase for instance
**cat** but in the directory that they are telling the script to look at to
find the phrase the word is spelled **Cat** or **CAt** or **CAT** or **cAT**
it will still return showing the phrase is in the directory and where it is. I
have attached my code below:

    
    
    import os
    
    phrase_to_look_for = input("What phrase would you like to look for?")
    name_of_directory = input("What is the name of your directory?")
    for subdir, dirs, files in os.walk(name_of_directory, phrase_to_look_for):
            for file in files:
                    file_path = os.path.join(name_of_directory, subdir, file)
                    file_to_search = open(file_path,'r')
                    try:
                            contents_of_file = file_to_search.read()
                    except:
                            contents_of_file = ''
                    if phrase_to_look_for in contents_of_file:
                            print("The word is in the file: " + file)
                    else:
                            print("The phrase is not in the file.")
    

Thanks for your help in advance.


Answer: Simply `lower` the file contents and the users input:

    
    
    phrase_to_look_for = input("What phrase would you like to look for?").lower() 
    

and

    
    
    contents_of_file = file_to_search.read().lower()
    

This will make everything lowercase, effectively making your search case
insensitive. I should point out that your empty `except` should be what you
actually want to be handling, namely `except IOError:`

