lib/matplotlib/mlab.py
def rec2csv(r, fname, delimiter=',', formatd=None, missing='',
            missingd=None, withheader=True):
    """
    Save the data from numpy recarray *r* into a
    comma-/space-/tab-delimited file.  The record array dtype names
    will be used for column headers.

    *fname*: can be a filename or a file handle.  Support for gzipped
      files is automatic, if the filename ends in '.gz'

    *withheader*: if withheader is False, do not write the attribute
      names in the first row

    for formatd type FormatFloat, we override the precision to store
    full precision floats in the CSV file


    .. seealso::

        :func:`csv2rec`
            For information about *missing* and *missingd*, which can
            be used to fill in masked values into your CSV file.
    """

    if missingd is None:
        missingd = dict()

    def with_mask(func):
        def newfunc(val, mask, mval):
            if mask:
                return mval
            else:
                return func(val)
        return newfunc

    formatd = get_formatd(r, formatd)
    funcs = []
    for i, name in enumerate(r.dtype.names):
        funcs.append(with_mask(csvformat_factory(formatd[name]).tostr))

    fh, opened = cbook.to_filehandle(fname, 'wb', return_opened=True)
    writer = csv.writer(fh, delimiter=delimiter)
    header = r.dtype.names
    if withheader:
        writer.writerow(header)

    # Our list of specials for missing values
    mvals = []
    for name in header:
        mvals.append(missingd.get(name, missing))

    ismasked = False
    if len(r):
        row = r[0]
        ismasked = hasattr(row, '_fieldmask')

    for row in r:
        if ismasked:
            row, rowmask = row.item(), row._fieldmask.item()
        else:
            rowmask = [False] * len(row)
        writer.writerow([func(val, mask, mval) for func, val, mask, mval
                         in zip(funcs, row, rowmask, mvals)])
    if opened:
        fh.close()

    Save the data from numpy recarray *r* into a
    comma-/space-/tab-delimited file.  The record array dtype names
    will be used for column headers.

    *fname*: can be a filename or a file handle.  Support for gzipped
      files is automatic, if the filename ends in '.gz'

    *withheader*: if withheader is False, do not write the attribute
      names in the first row

    for formatd type FormatFloat, we override the precision to store
    full precision floats in the CSV file


    .. seealso::

        :func:`csv2rec`
            For information about *missing* and *missingd*, which can
            be used to fill in masked values into your CSV file.
    
Save the data from numpy recarray *r* into a
comma-/space-/tab-delimited file.  The record array dtype names
will be used for column headers.

fname*: can be a filename or a file handle.  Support for gzipped
files is automatic, if the filename ends in '.gz'

withheader*: if withheader is False, do not write the attribute
names in the first row

for formatd type FormatFloat, we override the precision to store
full precision floats in the CSV file



:func:`csv2rec`
For information about *missing* and *missingd*, which can
be used to fill in masked values into your CSV file.
Save the data from numpy recarray * r * into a comma - / space - / tab - delimited file . The record array dtype names will be used for column headers . fname * : can be a filename or a file handle . Support for gzipped files is automatic if the filename ends in ' . gz ' withheader * : if withheader is False do not write the attribute names in the first row for formatd type FormatFloat we override the precision to store full precision floats in the CSV file : func : ` csv2rec ` For information about * missing * and * missingd * which can be used to fill in masked values into your CSV file .
def rec2csv(r, fname, delimiter=',', formatd=None, missing='',
            missingd=None, withheader=True):
    if missingd is None:
        missingd = dict()
    def with_mask(func):
        def newfunc(val, mask, mval):
            if mask:
                return mval
            else:
                return func(val)
        return newfunc
    formatd = get_formatd(r, formatd)
    funcs = []
    for i, name in enumerate(r.dtype.names):
        funcs.append(with_mask(csvformat_factory(formatd[name]).tostr))
    fh, opened = cbook.to_filehandle(fname, 'wb', return_opened=True)
    writer = csv.writer(fh, delimiter=delimiter)
    header = r.dtype.names
    if withheader:
        writer.writerow(header)
    mvals = []
    for name in header:
        mvals.append(missingd.get(name, missing))
    ismasked = False
    if len(r):
        row = r[0]
        ismasked = hasattr(row, '_fieldmask')
    for row in r:
        if ismasked:
            row, rowmask = row.item(), row._fieldmask.item()
        else:
            rowmask = [False] * len(row)
        writer.writerow([func(val, mask, mval) for func, val, mask, mval
                         in zip(funcs, row, rowmask, mvals)])
    if opened:
        fh.close()
def rec2csv ( r , fname , delimiter = ',' , formatd = None , missing = '' , missingd = None , withheader = True ) : if missingd is None : missingd = dict ( ) def with_mask ( func ) : def newfunc ( val , mask , mval ) : if mask : return mval else : return func ( val ) return newfunc formatd = get_formatd ( r , formatd ) funcs = [ ] for i , name in enumerate ( r . dtype . names ) : funcs . append ( with_mask ( csvformat_factory ( formatd [ name ] ) . tostr ) ) fh , opened = cbook . to_filehandle ( fname , 'wb' , return_opened = True ) writer = csv . writer ( fh , delimiter = delimiter ) header = r . dtype . names if withheader : writer . writerow ( header ) mvals = [ ] for name in header : mvals . append ( missingd . get ( name , missing ) ) ismasked = False if len ( r ) : row = r [ 0 ] ismasked = hasattr ( row , '_fieldmask' ) for row in r : if ismasked : row , rowmask = row . item ( ) , row . _fieldmask . item ( ) else : rowmask = [ False ] * len ( row ) writer . writerow ( [ func ( val , mask , mval ) for func , val , mask , mval in zip ( funcs , row , rowmask , mvals ) ] ) if opened : fh . close ( )
Save the data from numpy recarray *r* into a
comma-/space-/tab-delimited file.
Save the data from numpy recarray * r * into a comma - / space - / tab - delimited file .
"""
    Save the data from numpy recarray *r* into a
    comma-/space-/tab-delimited file.  The record array dtype names
    will be used for column headers.

    *fname*: can be a filename or a file handle.  Support for gzipped
      files is automatic, if the filename ends in '.gz'

    *withheader*: if withheader is False, do not write the attribute
      names in the first row

    for formatd type FormatFloat, we override the precision to store
    full precision floats in the CSV file


    .. seealso::

        :func:`csv2rec`
            For information about *missing* and *missingd*, which can
            be used to fill in masked values into your CSV file.
    """ # Our list of specials for missing values
r
fname
delimiter
formatd
missing
missingd
withheader