标签:author def port color dump open write pre int
json:
# _author: lily # _date: 2019/1/19 import json my_dict = {‘name‘: ‘lily‘, ‘age‘: 18} f = open(‘JSON_text‘, ‘w‘) # data = json.dumps(my_dict) # f.write(data) # 上面两句等价于 json.dump(my_dict, f) f.close()
# _author: lily # _date: 2019/1/20 import json f = open(‘JSON_text‘, ‘r‘) # data = f.read() # my_dict = json.loads(data) # 上面两句话等价于 my_dict = json.load(f) print(my_dict[‘name‘]) f.close()
pickle:
# _author: lily # _date: 2019/1/20 import pickle def foo(): print(‘ok‘) data = pickle.dumps(foo) f = open(‘PICKLE_text‘, ‘wb‘) f.write(data) f.close()
# _author: lily # _date: 2019/1/20 import pickle def foo(): print(‘okok‘) f = open(‘PICKLE_text‘, ‘rb‘) data = f.read() data = pickle.loads(data) data() f.close()
shelve:
# _author: lily # _date: 2019/1/20 import shelve # f = shelve.open(‘SHELVE_text‘) # f[‘info‘] = {‘name‘: ‘lily‘, ‘age‘: 18} f = shelve.open(‘SHELVE_text‘) data = f.get(‘info‘) print(data[‘name‘])
标签:author def port color dump open write pre int
原文地址:https://www.cnblogs.com/mlllily/p/10294900.html