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.
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)
When I open the dict_read.py file I am just seeing an empty dict:
{}
Where am I going wrong?
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:
form = cgi.FieldStorage()
latitude = form.getvalue('latitude')
s = open('any_read.py','w')
s.write(str(latitude))
s.close()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.