title: Python Increasing counter by 1 every time something is written to a file
body: <p>What I'm trying to do is every time the file 'TCPStreamPayload' is written to I want a counter that increases every time that information is appended to the file.</p>
  
  <p>For example I have:</p>
  
  <pre><code>payloadRecon = open('TCPStreamPayload.txt','a')
  
  segmentCount = 0
  
  --my script here--
  </code></pre>
  
  <p>then at the bottom</p>
  
  <pre><code>if payloadRecon.write:
      segmentCount +=1
  payloadRecon.write('####TCP PAYLOAD STREAM RECONSTRUCTION. Segment ' + str(segmentCount) + '######' '\n\n\n\n').
  </code></pre>
  
  <p>Basically, everytime I write to this file using my script I want the segment number to increase by 1.</p>