def load(filename): with lzma.open(filename, 'rb') as dataset: while True: try: yield pickle.load(dataset) except EOFError: break