# -*- coding: utf-8 -*-
"""
Created on Sat Oct 14 13:20:51 2017

@author: Tidus
"""

import os
import pickle

class MyDes:
    saved = []
    
    def __init__(self, name = None):
        self.name = name
        self.filename = self.name + '.pkl'
        
    def __get__(self, instance, owner):
        if self.name not in MyDes.saved:
            raise AttributeError('%s属性还未被赋值!'%self.name)
        
        with open(self.filename, 'rb') as f:
            value = pickle.load(f)
            
        return value
    
    def __set__(self, instance, value):
        with open(self.filename, 'wb') as f:
            pickle.dump(value, f)
            MyDes.saved.append(self.name)
            
    def __delete__(self, instance):
        os.remove(self.filename)
        MyDes.saved.remove(self.name)