title: Python prints error message io.UnsupportedOperation: not readable
body: <p>I have searched this site for similar issues, but have not found any solutions that worked, hence, this question.
  I am writing a Python 3.4 program in which I have a function, export, that essentially appends data to a text file. 
  The function checks to make sure that there is an appropriate file, if not, it creates one, and then it gets the contents of the file, adds the addendum, and overwrites the file. 
  Python is throwing the error at <code>for line in file:</code> Also, upon running this program again, once the text file is already created, this error doesn't occur.
  Here is the function:</p>
  
  <pre><code>def export(addendum, user):
      filename = user + '.txt'
      try:
          file = open(filename, 'r')
      except OSError:
          file = open(filename, 'w')
          export(addendum, user)
      file_contents = ''
      print('What day is it? (1-5)')
      day = input()
      day = int(day)
      if day &gt;= 1 and day &lt;= 5:
          for line in file:
              file_contents += line
          file = open(filename, 'w')
          new_file = file_contents + '\n' + addendum
          file.write(new_file)
          file.close()
      else:
          print('Invalid weekday number...')
          sys.exit()
  </code></pre>