turntable/utils.py
def to_pickle(obj, filename, clean_memory=False):
    '''http://stackoverflow.com/questions/7900944/read-write-classes-to-files-in-an-efficent-way'''

    path, filename = path_to_filename(filename)
    create_dir(path)

    with open(path + filename, "wb") as output:
        pickle.dump(obj, output, pickle.HIGHEST_PROTOCOL)

    if clean_memory:
        obj = None

    # setting the global object to None requires a return assignment
    return obj
def to_pickle(obj, filename, clean_memory=False):
    '''http://stackoverflow.com/questions/7900944/read-write-classes-to-files-in-an-efficent-way'''

    path, filename = path_to_filename(filename)
    create_dir(path)

    with open(path + filename, "wb") as output:
        pickle.dump(obj, output, pickle.HIGHEST_PROTOCOL)

    if clean_memory:
        obj = None

    # setting the global object to None requires a return assignment
    return obj
http://stackoverflow.com/questions/7900944/read-write-classes-to-files-in-an-efficent-way