def csviter(obj, delimiter=None, headers=None, encoding=None):
 encoding = (obj.encoding if isinstance(obj, TextResponse) else (encoding or 'utf-8'))
 def _getrow(csv_r):
  return [str_to_unicode(field, encoding) for field in csv_r.next()]
 lines = StringIO(body_or_str(obj, unicode=False))
 if delimiter:
  csv_r = csv.reader(lines, delimiter=delimiter)
 else:
  csv_r = csv.reader(lines)
 if (not headers):
  headers = _getrow(csv_r)
 while True:
  row = _getrow(csv_r)
  if (len(row) != len(headers)):
   log.msg(('ignoring row %d (length: %d, should be: %d)' % (csv_r.line_num, len(row), len(headers))), log.WARNING)
   continue
  else:
   (yield dict(zip(headers, row)))

def csviter ( obj , delimiter = None , headers = None , encoding = None ) : encoding = ( obj . encoding if isinstance ( obj , TextResponse ) else ( encoding or 'utf-8' ) ) def _getrow ( csv_r ) : return [ str_to_unicode ( field , encoding ) for field in csv_r . next ( ) ] lines = StringIO ( body_or_str ( obj , unicode = False ) ) if delimiter : csv_r = csv . reader ( lines , delimiter = delimiter ) else : csv_r = csv . reader ( lines ) if ( not headers ) : headers = _getrow ( csv_r ) while True : row = _getrow ( csv_r ) if ( len ( row ) != len ( headers ) ) : log . msg ( ( 'ignoring row %d (length: %d, should be: %d)' % ( csv_r . line_num , len ( row ) , len ( headers ) ) ) , log . WARNING ) continue else : ( yield dict ( zip ( headers , row ) ) )
returns an iterator of dictionaries from the given csv object obj can be: - a response object - a unicode string - a string encoded as utf-8 delimiter is the character used to separate field on the given obj .