首页 > 其他 > 详细

使用pickle模块存储对象

时间:2017-12-16 14:31:14      阅读:222      评论:0      收藏:0      [点我收藏+]
import time
import hashlib
import pickle
import os
class Info():
    def __init__(self):
        self.create_time=time.time()

    def md5(self):
        m=hashlib.md5()
        m.update(str(self.create_time).encode(utf-8))
        return m.hexdigest()
    def save(self):
        if not os.path.exists(md5):
            os.mkdir(md5)
        os.chdir(md5)
        print(self.md5())
        with open(self.md5(),wb) as f:
            pickle.dump(self,f)
    @staticmethod
    def read():
        path=rC:\Users\Administrator\模块\md5
        res=os.listdir(path)
        for item in res:
            file_path=r%s\%s%(path,item)
            # print(file_path)
            with open(file_path,rb) as f:
                # print(f)
                try:
                    obj=pickle.load(f)
                except Exception as e:
                    pass
                print(obj.create_time)

i=Info()
print(i.md5())
i.save()
i.read()

 

使用pickle模块存储对象

原文:http://www.cnblogs.com/ldq1996/p/8046319.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!