将字典写入文本文件,并取出
ab={'lee':21,'liu':18,'ma':20,'gao':22}
#字典写入文件
def write_dict(d):
with open('dict.txt','w') as file:
file.write(json.dumps(d))
#字典从文件中读出
def read_dict():
with open('dict.txt','r') as file:
st=file.read()
return json.loads(st)

浙公网安备 33010602011771号