def to_pickle(obj, filename, clean_memory=False):
path, filename = path_to_filename(filename)<EOL>create_dir(path)<EOL>with open(path + filename, "<STR_LIT:wb>") as output:<EOL><INDENT>pickle.dump(obj, output, pickle.HIGHEST_PROTOCOL)<EOL><DEDENT>if clean_memory:<EOL><INDENT>obj = None<EOL><DEDENT>return obj<EOL>
http://stackoverflow.com/questions/7900944/read-write-classes-to-files-in-an-efficent-way