title: Reading from a .txt file dynamically with Python
body: <p>I have a text file that will be populated depending on a radio button selected by a user in php</p>
  
  <p>I am reading from the same text file, whenever I find that a new line has been added the Python script prints it. For now I am just printing it. Eventually I will send out a message on a GSM modem based on the new records in the .txt file. Right now I'm just printing it to make sure I can identify a new record.</p>
  
  <p>Here's the code I'm using. It works just fine. </p>
  
  <pre><code>def main():
      flag = 0
      count = 0
      while flag == 0:
          f = open('test.txt', 'r')
          with open('test.txt') as f:
              for i, l in enumerate(f):
                  pass
          nol = i + 1
          if count &lt; nol:
              while count &lt;= nol:
                  f = open('test.txt', 'r')
                  a = f.readlines(count)
                  if count == 0:
                      print a[0]
                      count = count+2
                  else:
                      print a[count-1]
                      count = count+1
  if __name__ ==  '__main__':
      main()
  </code></pre>
  
  <p>I was wondering if there is a better way to do this.</p>
  
  <p>Also, php will keep writing to the file. And python will keep reading from it. Will this cause a clash? Since multiple instance are open?</p>