title: Reading files and writing to database in django
body: <p>I have a Django app that opens a file, continuously reads it, and at the same time writes data to a Postgres database.  My issue is that whenever I open a file, </p>
  
  <pre><code>file = open(filename, 'r')
  </code></pre>
  
  <p>I am unable to also create new things in the database,</p>
  
  <pre><code>Message.objects.create_message(sys, msg)
  </code></pre>
  
  <p>That should create a database entry with two strings.  However, nothing seems to happen and I am presented with no errors :( If I decide to close the file, <code>file.close()</code>, before I write to the database everything is fine.  My problem is that I need that file open to create my objects.  Does anyone have a solution for this?  Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here's some more of my code.  Basically I have the following snippet following the end of a file and then writing to the database as it gets information.</p>
  
  <pre><code>file.seek(0,2)         
  while True:
    line = file.readline()
    if not line:
      time.sleep(1)
      continue
    Message.objects.create_message(sys, line)
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Got this to work finally but I'm not sure why.  I'd love to understand why this worked:</p>
  
  <pre><code>str1ng = line[0:len(line)-1]
  Message.objects.create_message(sys, str1ng)
  </code></pre>
  
  <p>Some how there is a difference between that string and the string gathered from file.readline().
  Any ideas?</p>