Write a notebook to a file

def write(notebook, file_or_stream, fmt, version=nbformat.NO_CONVERT, **kwargs):
    """Write a notebook to a file"""
    # Python 2 compatibility
    text = u'' + writes(notebook, fmt, version, **kwargs)
    file_or_stream.write(text)
    # Add final newline #165
    if not text.endswith(u'\n'):
        file_or_stream.write(u'\n')