title: How to write a dictionary into an existing file?
body: <p>Let's say I have a dictionary and I want to write it into an existing file. How can I do so without losing anything that could potentially already exist in the file? What I was thinking of is doing the following:</p>
  
  <pre><code>def write_report(r, filename):
          input_filename=open(filename, "a")
          input_filename.close()
          for (k,v) in r.items():
                 input_filename.write(k,v)
          return filename
  </code></pre>
  
  <p>what I want to make sure is that the filename correctly contains the dictionary.</p>