如何将带有列表键的 python 字典保存到文件中?我试过 json,但它说它只适用于字符串键,我的字典看起来像这样:
{(24222, 64130): 'whatever', (24270, 64130): 'whatever', (24240, 64130): 'whatever'}
而且我必须保持这种形式。 感谢您的帮助!
请您参考如下方法:
将你的字典转换成字符串并写入文件。
dict_val = {(24222, 64130): 'whatever', (24270, 64130): 'whatever', (24240, 64130): 'whatever'}
with open('file.txt','w') as f:
f.write(str(dict_val))
