[Ilugc] using dictreader in python

  • From: lawgon@xxxxxxxxxxxxxxx (Kenneth Gonsalves)
  • Date: Wed Nov 4 13:34:31 2009

On Wednesday 04 Nov 2009 1:21:15 pm Siva Subramanian wrote:

I am now trying to access the csv file using dictreader.

<quote>
class csv.DictReader(csvfile[, fieldnames=None[, restkey=None[, restval=None[, 
dialect='excel'[, *args, **kwds]]]]])?
    Create an object which operates like a regular reader but maps the 
information read into a dict whose keys are given by the optional fieldnames 
parameter. If the fieldnames parameter is omitted, the values in the first row 
of the csvfile will be used as the fieldnames. If the row read has fewer fields 
than the fieldnames sequence, the value of restval will be used as the default 
value. If the row read has more fields than the fieldnames sequence, the 
remaining data is added as a sequence keyed by the value of restkey. If the 
row read has fewer fields than the fieldnames sequence, the remaining keys take 
the value of the optional restval parameter. Any other optional or keyword 
arguments are passed to the underlying reader instance.
</unquote>

use the fieldname parameter which will give you a dictionary with all values. 
If you put this in a database, then sql power is available for all sorts of 
queries.
-- 
regards
kg
http://lawgon.livejournal.com

Other related posts: