def _read_csv(filepath, kwargs):
    """See documentation of mpu.io.read."""
    if 'delimiter' not in kwargs:
        kwargs['delimiter'] = ','
    if 'quotechar' not in kwargs:
        kwargs['quotechar'] = '"'
    if 'skiprows' not in kwargs:
        kwargs['skiprows'] = []
    if isinstance(kwargs['skiprows'], int):
        kwargs['skiprows'] = [i for i in range(kwargs['skiprows'])]
    if 'format' in kwargs:
        format_ = kwargs['format']
        kwargs.pop('format', None)
    else:
        format_ = 'default'
    skiprows = kwargs['skiprows']
    kwargs.pop('skiprows', None)

    kwargs_open = {'newline': ''}
    mode = 'r'
    if sys.version_info < (3, 0):
        kwargs_open.pop('newline', None)
        mode = 'rb'
    with open(filepath, mode, **kwargs_open) as fp:
        if format_ == 'default':
            reader = csv.reader(fp, **kwargs)
            data = EList([row for row in reader])
            data = data.remove_indices(skiprows)
        elif format_ == 'dicts':
            reader_list = csv.DictReader(fp, **kwargs)
            data = [row for row in reader_list]
        else:
            raise NotImplementedError('Format \'{}\' unknown'
                                      .format(format_))
    return data
def _read_csv ( filepath , kwargs ) : if 'delimiter' not in kwargs : kwargs [ 'delimiter' ] = ',' if 'quotechar' not in kwargs : kwargs [ 'quotechar' ] = '"' if 'skiprows' not in kwargs : kwargs [ 'skiprows' ] = [ ] if isinstance ( kwargs [ 'skiprows' ] , int ) : kwargs [ 'skiprows' ] = [ i for i in range ( kwargs [ 'skiprows' ] ) ] if 'format' in kwargs : format_ = kwargs [ 'format' ] kwargs . pop ( 'format' , None ) else : format_ = 'default' skiprows = kwargs [ 'skiprows' ] kwargs . pop ( 'skiprows' , None ) kwargs_open = { 'newline' : '' } mode = 'r' if sys . version_info < ( 3 , 0 ) : kwargs_open . pop ( 'newline' , None ) mode = 'rb' with open ( filepath , mode , ** kwargs_open ) as fp : if format_ == 'default' : reader = csv . reader ( fp , ** kwargs ) data = EList ( [ row for row in reader ] ) data = data . remove_indices ( skiprows ) elif format_ == 'dicts' : reader_list = csv . DictReader ( fp , ** kwargs ) data = [ row for row in reader_list ] else : raise NotImplementedError ( 'Format \'{}\' unknown' . format ( format_ ) ) return data
See documentation of mpu.io.read.