kitir/_libs/file_utils.py
def write_csv(file_name, contents, headers=None, **kwargs):
    """
    writes a csv file using DictWriter and returns the filename
    if contents is a rowdicts uses the keys of the first dict in contents as the headers
    if contents is a dictionary, you must supply the headers, for 2 columns [key, value]
    :param file_name: path of the file
    :param contents: rowdicts list (or simple dict/map with all strings, for 2 columns [key, value]
    :param headers: specify headers, or take from contents
    :return: the filename that was written
    """
    filemode = kwargs.pop('filemode', 'w')
    if isinstance(contents, dict):
        assert headers and len(headers) == 2
        contents = [{headers[0]: key, headers[1]: value} for key, value in contents.items()]
    headers = headers or contents[0].keys()
    log.trace('writing csv file: path={} headers={} rows={}'.format(file_name, headers, len(contents)))
    check_makedir(os.path.dirname(file_name))
    with open(file_name, filemode) as f:
        writer = DictWriter(f, headers, **kwargs)
        writer.writeheader()
        writer.writerows(contents)
    return file_name

    writes a csv file using DictWriter and returns the filename
    if contents is a rowdicts uses the keys of the first dict in contents as the headers
    if contents is a dictionary, you must supply the headers, for 2 columns [key, value]
    :param file_name: path of the file
    :param contents: rowdicts list (or simple dict/map with all strings, for 2 columns [key, value]
    :param headers: specify headers, or take from contents
    :return: the filename that was written
    
writes a csv file using DictWriter and returns the filename
if contents is a rowdicts uses the keys of the first dict in contents as the headers
if contents is a dictionary, you must supply the headers, for 2 columns [key, value]
writes a csv file using DictWriter and returns the filename if contents is a rowdicts uses the keys of the first dict in contents as the headers if contents is a dictionary you must supply the headers for 2 columns [ key value ]
def write_csv(file_name, contents, headers=None, **kwargs):
    filemode = kwargs.pop('filemode', 'w')
    if isinstance(contents, dict):
        assert headers and len(headers) == 2
        contents = [{headers[0]: key, headers[1]: value} for key, value in contents.items()]
    headers = headers or contents[0].keys()
    log.trace('writing csv file: path={} headers={} rows={}'.format(file_name, headers, len(contents)))
    check_makedir(os.path.dirname(file_name))
    with open(file_name, filemode) as f:
        writer = DictWriter(f, headers, **kwargs)
        writer.writeheader()
        writer.writerows(contents)
    return file_name
def write_csv ( file_name , contents , headers = None , ** kwargs ) : filemode = kwargs . pop ( 'filemode' , 'w' ) if isinstance ( contents , dict ) : assert headers and len ( headers ) == 2 contents = [ { headers [ 0 ] : key , headers [ 1 ] : value } for key , value in contents . items ( ) ] headers = headers or contents [ 0 ] . keys ( ) log . trace ( 'writing csv file: path={} headers={} rows={}' . format ( file_name , headers , len ( contents ) ) ) check_makedir ( os . path . dirname ( file_name ) ) with open ( file_name , filemode ) as f : writer = DictWriter ( f , headers , ** kwargs ) writer . writeheader ( ) writer . writerows ( contents ) return file_name
writes a csv file using DictWriter and returns the filename
if contents is a rowdicts uses the keys of the first dict in contents as the headers
if contents is a dictionary, you must supply the headers, for 2 columns [key, value]
writes a csv file using DictWriter and returns the filename if contents is a rowdicts uses the keys of the first dict in contents as the headers if contents is a dictionary you must supply the headers for 2 columns [ key value ]
"""
    writes a csv file using DictWriter and returns the filename
    if contents is a rowdicts uses the keys of the first dict in contents as the headers
    if contents is a dictionary, you must supply the headers, for 2 columns [key, value]
    :param file_name: path of the file
    :param contents: rowdicts list (or simple dict/map with all strings, for 2 columns [key, value]
    :param headers: specify headers, or take from contents
    :return: the filename that was written
    """
the filename that was written
the filename that was written
file_name
path of the file
path of the file
contents
rowdicts list (or simple dict/map with all strings, for 2 columns [key, value]
rowdicts list ( or simple dict / map with all strings for 2 columns [ key value ]
headers
specify headers, or take from contents
specify headers or take from contents