I have a dictionary and am trying to write it to a file.
exDict = {1:1, 2:2, 3:3}
with open('file.txt', 'r') as file:
file.write(exDict)
I then have the error
file.write(exDict)
TypeError: must be str, not dict
So I fixed that error but another error came
exDict = {111:111, 222:222}
with open('file.txt', 'r') as file:
file.write(str(exDict))
The error:
file.write(str(exDict))
io.UnsupportedOperation: not writable
I have no idea what to do as I am still a beginner at python.
If anyone knows how to resolve the issue, please provide an answer.
NOTE: I am using python 3, not python 2
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…