title: deleting file if it exists; python
body: <p>I want to create a file; if it already exists I want to delete it and create it anew. I tried doing it like this but it throws a Win32 error. What am I doing wrong?</p>
  
  <pre><code>try:
      with open(os.path.expanduser('~') + '\Desktop\input.txt'):
          os.remove(os.path.expanduser('~') + '\Desktop\input.txt')
          f1 = open(os.path.expanduser('~') + '\Desktop\input.txt', 'a')
  except IOError:
      f1 = open(os.path.expanduser('~') + '\Desktop\input.txt', 'a')
  </code></pre>