<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def store(self, result, filename, pretty=True):
 """ Write a result to the given file. Parameters result : memote.MemoteResult The dictionary structure of results. filename : str or pathlib.Path Store results directly to the given filename. pretty : bool, optional Whether (default) or not to write JSON in a more legible format. """

        LOGGER.info("Storing result in '%s'.", filename)
        if filename.endswith(".gz"):
            with gzip.open(filename, "wb") as file_handle:
                file_handle.write(
                    jsonify(result, pretty=pretty).encode("utf-8")
                )
        else:
            with open(filename, "w", encoding="utf-8") as file_handle:
                file_handle.write(jsonify(result, pretty=pretty))