码迷,mamicode.com
首页 > 其他好文 > 详细

pickle模块

时间:2018-12-15 13:41:28      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:import   toc   print   nbsp   init   port   dump   save   coding   

# -*- 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()

 

pickle模块

标签:import   toc   print   nbsp   init   port   dump   save   coding   

原文地址:https://www.cnblogs.com/xaiobong/p/10122691.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!