title: Wait for text file to be written, read changes line by line and print
body: <p>I have the below code, which waits for a log file to appear, it's being saved there by an external programme, when the log file appears I open it, while it's still being written to, and print the contents, as the log file is being updated by the external programme I want to print out any new lines being written to it. Currently I clear the print out and re-print the entire text, which I would like to avoid, I would like to only print the new lines. Another thing to improve is waiting for the file to appear, rather than just pausing the python script.</p>
  
  <pre><code>    a=0
      while a &lt;= 10:
          if os.path.isfile(logPath):
              infile = file(logPath)
              break
          a=a+1
          time.sleep(1)
      fileSize1 = 0
      while True:
          wx.Yield()
          fileSize = os.path.getsize(logPath)
          if fileSize &gt; fileSize1:
              lines = infile.readlines()
              log.Clear()
              log.Refresh()
              for line in lines:
                  print line.rstrip()
              if "DBG-X: Returning 1" in line:
                  break
              if "DBG-X: Returning 0" in line:
                  break
          fileSize1 = fileSize
          infile.seek(0)
  </code></pre>