def write_document ( doc , fnm ) : with codecs . open ( fnm , 'wb' , 'ascii' ) as f : f . write ( json . dumps ( doc , indent = 2 ) )
how to write to a document without erasing python
Write a Text document to file .
def write_document(doc, fnm):
    """Write a Text document to file.

    Parameters
    ----------
    doc: Text
        The document to save.
    fnm: str
        The filename to save the document
    """
    with codecs.open(fnm, 'wb', 'ascii') as f:
        f.write(json.dumps(doc, indent=2))