title: writing counter with python
body: <p>I am writing a counter for my webpage using python. And my code is as follow:</p>
  
  <pre><code>#!/usr/bin/python 
  print """#Content-type: text/html\r\n\r\n 
  &lt;html&gt;
  &lt;center&gt;
  &lt;p&gt;The webpage has been accessed for&lt;/p&gt;"""
  f=open( "number.txt", "r" )
  count = f.read()
  n = int( count )
  f.close()
  f=open( "number.txt", "w" )
  f.write( str(n+1) ) 
  f.close()
  print "&lt;p&gt;"+count+"&lt;/p&gt;"
  print """&lt;p&gt;times&lt;/p&gt;
  &lt;/center&gt;
  &lt;/html&gt;
  """ 
  </code></pre>
  
  <p>When I opened the webpage, only half of the page can be shown. Then I opened the source code of the page, only the following code was shown:</p>
  
  <pre><code>&lt;html&gt;
  &lt;center&gt;
  &lt;p&gt;The webpage has been accessed for&lt;/p&gt;
  </code></pre>
  
  <p>After that, I tried another version:</p>
  
  <pre><code>#!/usr/bin/python 
  print """#Content-type: text/html\r\n\r\n 
  &lt;html&gt;
  &lt;center&gt;
  &lt;p&gt;The webpage has been accessed for&lt;/p&gt;"""
  f=open( "number.txt", "r" )
  count = f.read()
  n = int( count )
  print "&lt;p&gt;"+count+"&lt;/p&gt;"
  print """&lt;p&gt;times&lt;/p&gt;
  &lt;/center&gt;
  &lt;/html&gt;
  """ 
  f.close()
  f=open( "number.txt", "w" )
  f.write( str(n+1) ) 
  f.close()
  </code></pre>
  
  <p>It works better but not what I expected:</p>
  
  <pre><code>&lt;html&gt;
  &lt;center&gt;
  &lt;p&gt;The webpage has been accessed for&lt;/p&gt;
  &lt;p&gt;40&lt;/p&gt;
  &lt;p&gt;times&lt;/p&gt;
  &lt;/center&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The code is ok but I found that the counter can't update itself!
  What can I do about it?</p>