
Matthew P. answered 10/09/19
Software Engineer with BSE degree in Computer Science
You are trying to write a dictionary as if it were a string. Fortunately, Python has a `json` package that makes your task very simple! To write JSON data (stored as a Python dictionary) to a file, use the json.dump() function:
Alternatively, if you wanted to convert your JSON data to a string without writing it to a file right away, there is another function you can use, json.dumps(). This will allow you to do string manipulations if you wish. Once you have your JSON string in its final form, you can write it to a file like you were trying to do.