

def export_pickle(data, filename='test.dat', compress=False):
    fh = None
    try:
        if compress:
            fh = gzip.open(filename, 'wb')
        else:
            fh = open(filename, 'wb')
            pickle.dump(data, fh, pickle.HIGHEST_PROTOCOL)
    except (EnvironmentError, pickle.PickingError) as err:
        print('{0}: export error: {1}'.format(os.path.basename(sys.argv[0], err)))
        return False
    finally:
        if (fh is not None):
            fh.close()

dataset/ETHPy150Open bt3gl/Python-and-Algorithms-and-Data-Structures/src/USEFUL/basic_examples/example_pickle.py export_pickle/original