Read file error in Python, even though print function is printing the list
<p>I have been trying different ways of writing this code but cannot get past this.  Currently the program will run all the way to the <code>write_names(list)</code> function and create the file, and the print function will print the sorted list.  The program refuses to get the user input for the <code>search_names()</code> function but it will print anything I ask it to.  </p>

<p>Debug highlights: <code>while index &lt; len(list)</code> and in the debug I\O only states "read file error".  Hopefully someone has an idea what I'm doing wrong. </p>

<pre><code>'#  Abstract:     This program creates a list of names.  The list is printed,
'#                sorted, printed again, written to file, and searched.
'#=============================================================================

'#define the main function

def main():

    #try:
        ##open data file for read
        #infile = open('names.txt', 'r')

    #call get_names function
    list = get_names()

    #call print function
    print_names(list)

    #sort list
    list.sort()

    #print sorted list
    print_names(list)

    #write sorted list to new file
    write_names(list)

    #allow user to search list
    search_names(list)



def get_names():

    try:
        infile = open('names.txt', 'r')
        #read file contents into a list
        list = infile.readlines()
        #close file
        infile.close()
        #strip \n from each element
        index = 0
        while index &lt; len(list):
            list[index] = list[index].rstrip('\n')
            index += 1
        return list
    except IOError:
        print 'Read file error'

def print_names(list):

    #print header
    print '******************'
    #print list line by line
    index = 0
    while index &lt; len(list):
        print list[index]
        index += 1
    return

def write_names(list):

    #open file for writing
    outfile = open('sortedNames.txt', 'w')
    #write the list to the file
    for item in list:
        outfile.write(str(item) + '\n')
    #close file
    outfile.close()

def search_names(list):

    #set user test variable
    again = 'Y'
    while again.upper == 'Y':
        #get search from user   
        search = raw_input('Enter a name to search for: ')
        #open list for search
        if search in list:
            try:
                item_index = list.index(search)
                print search, 'found.', item_index
            except ValueError:
                print search, 'not found.'



main()
'
</code></pre>

<p>Thanks in advance!</p>
