title: How can I fix this error TypeError: '_io.TextIOWrapper' object is not subscriptable
body: <p>I keep getting this error in my program and I have no idea how to fix it. Here's where the error comes.</p>
  
  <pre><code>def check_file(): 
         for read in range(6):
         length = len(linecache.getline('status.py', read))
         f = linecache.getline('status.py', read)[0:length-1]
         print (f)
         if read &gt;= 6:
             print("5")
         else:
             file[read-1][1] = f
     return file
  
  def change_state(change_till, state): # changes tills' status
      global file
      data = ''
      status = check_file()
      status[change_till-1][1] = state
      file = open('status.py', 'w')
      file.write(status[0][1]+'\n'+status[1][1]+'\n'+status[2][1]+'\n'+status[3][1]+'\n'+status[4][1])
      file.close()
      return state
  </code></pre>
  
  <p>I run the code and this error comes up </p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 151, in &lt;module&gt;
      start()
    File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 144, in start
      state = check_status(this_till-1)
    File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 58, in check_status
      status = check_file()
    File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 21, in check_file
      file[read-1][1] = f
  TypeError: '_io.TextIOWrapper' object is not subscriptable.
  </code></pre>
  
  <p>Does anyone know why this happens and how to fix it?</p>