Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import os
- try:
- import cPickle as pickle
- except ImportError:
- import pickle
- class Thing:
- def __init__(self, s):
- self.s = s
- def __repr__(self):
- return 'Thing: %s' % self.s
- def save(self, filename):
- '''Save thing to a file.'''
- with open(filename, 'wb') as f:
- pickle.dump(self, f)
- @staticmethod
- def load(filename):
- ''' Return a thing loaded from file.'''
- with open(filename, 'rb') as f:
- obj = pickle.load(f)
- return obj
- def split_into_tokens(message):
- pass
- def split_into_lemmas(message):
- pass
- SAVE_FILE = 'thing.pkl'
- if __name__ == '__main__':
- if os.path.isfile(SAVE_FILE):
- t = Thing.load(SAVE_FILE)
- print('Loaded thing from disk:', SAVE_FILE)
- else:
- t = Thing('foo')
- t.save('thing.pkl')
- print('Saved thing to disk:', SAVE_FILE)
- print(t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement