pickle模块

# -*- coding: utf-8 -*-
# -- coding: utf-8 --
import pickle
class School():

    def __init__(self,name):

        self.name = name

    def save(self):

        # 写入
        with open('my', 'wb') as f:
            pickle.dump(self, f, pickle.HIGHEST_PROTOCOL)
        """
        # 读取
        with open('my', 'rb') as f:
            data = pickle.load(f)
        print(data.name)
        """

        print(self.name)

s1 = School("北海")
s1.save()

 

posted @ 2018-12-15 10:43  疯狂的骆驼  阅读(104)  评论(0编辑  收藏  举报