title: Python Check if files exists, If Yes Update it Else Create it
body: <p>I am new to Python 
  <strong>I want to check if a filename <code>checkzero.txt</code> exists</strong>
  If it does not exists, I want to write 1 in <code>checkzero.txt</code>, else I will increment it.</p>
  
  <pre><code>if os.path.exists("checkzero.txt"):
  
      f = open('checkzero.txt', 'r')
      counter = pickle.load(f)
      f.close()
  
      counter = counter + 1
  
      f = open('checkzero.txt', 'w')
      pickle.dump(counter, f)
      f.close()
  
  else:
      f = open('checkzero.txt', 'w')
      pickle.dump(1, f)
      f.close()
  </code></pre>
  
  <p>However if I create <code>checkzero.txt</code> as an empty file, it errors with:</p>
  
  <pre><code>Traceback (most recent call last):
    File "FileBasics.py", line 8, in &lt;module&gt;
      counter = pickle.load(f)
    File "/usr/local/Cellar/python/2.7.2/lib/python2.7/pickle.py", line 1378, in load
      return Unpickler(file).load()
    File "/usr/local/Cellar/python/2.7.2/lib/python2.7/pickle.py", line 858, in load
      dispatch[key](self)
    File "/usr/local/Cellar/python/2.7.2/lib/python2.7/pickle.py", line 880, in load_eof
      raise EOFError
  EOFError
  </code></pre>