原文来源:https://stackoverflow.com/questions/36965507/writing-a-dictionary-to-a-text-file 我有一个字典,我打算把它写入一个文件. exDict = {1:1, 2:2, 3:3} with open('file.txt', 'r') as file: file.write(exDict) 我遇到了这样的错误: file.write(exDict) TypeError: must be str, not dict 我