Occurs when writing non-string data to a file.
data = {
"name": "john",
"age": 30
}
with open("output.txt", "w") as file:
file.write(data)TypeError: write() argument must be str, not dict
import json
data = {
"name": "john",
"age": 30
}
with open("output.txt", "w") as file:
file.write(json.dumps(data))Tried to write a dict directly without converting it to a string.