之前已经写过dumps和loads方法,dump和load方法就是对他们的一个简化
import pickle
import json
if __name__ == '__main__':
d = {'aaa': 111, 'bbb': 222}
fd = open('../log/jsonTest1.txt', 'w')
json.dump(d, fd)
fd.close()
fd = open('../log/jsonTest1.txt', 'r')
data = json.load(fd)
print(data['aaa'])
d = {'aaa': 111, 'bbb': 222}
fd = open('../log/pickleTest1.txt', 'wb')
pickle.dump(d, fd)
fd.close()
fd = open('../log/pickleTest1.txt', 'rb')
data = pickle.load(fd)
print(data['aaa'])