Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pickle
- class Pickles(object):
- def __init__(self):
- self.list = self._read_list_from_file()
- def _read_list_from_file(self):
- try:
- with open('list.pkl', 'r+') as f:
- self.list = pickle.loads(f.read())
- except (IOError, EOFError):
- return []
- return self.list
- def display_list(self):
- if self.list:
- print self.list
- else:
- print self._read_list_from_file()
- def _update_list(self):
- with open('list.pkl', 'w+') as f:
- f.write(pickle.dumps(self.list))
- def append_list(self, *args):
- if not self.list:
- self.list = []
- self.list.extend(args)
- self._update_list()
- if __name__ == '__main__':
- test = Pickles()
- test.append_list(1,2,3,4)
- test.display_list()
- test.append_list(5)
- test.display_list()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement