print cgi fieldstorage object to file instead of a html page python
<p>Thanks in advance. I have a dictionary that has been created from form post data. I want to print the contents of the dictionary to another file. I do not want to use it to output to a html page. </p>

<pre><code>def cgiFieldStorageToDict( fieldStorage ):
   # Makes a dictionary from the http post data
   params = {}
   for key in fieldStorage.keys():
      params[ key ] = fieldStorage[ key ].value
   return params



my_dict = cgiFieldStorageToDict( cgi.FieldStorage() )
s = open('dict_read.py','w')
z = str(my_dict)
s.write(z)
</code></pre>

<p>When I open the dict_read.py file I am just seeing an empty dict:</p>

<pre><code>{}
</code></pre>

<p>Where am I going wrong?</p>

<p>I could not write to the file because it did not have the right permissions for all users to write to it. I chmod the file to 777 and some of the code and it now works the way I want it too. Here is the code:</p>

<pre><code>form = cgi.FieldStorage()
latitude = form.getvalue('latitude')
s = open('any_read.py','w')
s.write(str(latitude))
s.close()
</code></pre>

python forms file post cgi