网站首页 文章专栏 use pickle module in python3
use pickle module in python3
创建于:2018-04-18 16:00:00 更新于:2024-04-25 13:08:29 羽瀚尘 683
python python,pickle

store data

import pickle
import os 
log_save_path = './log/'
log_name = "acc"
if  not os.path.exists(log_save_path):
    os.makedirs(log_save_path)
with open(log_save_path + log_name, 'wb') as f:
    pickle.dump(acc, f)

read data

import pickle
import os
log_save_path = './log/'
log_name = "acc"

# read a dict and put it into acc
acc = pickle.load(open('2018-04-23-13-35acc','rb'))

# transfer dict into items, it looks like (key1, value1), (key2, value2)
items = list(acc.items())

# form keys and values
# sometimes we need a vector of keys and values

keys, values = tuple(zip(*items))