Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

using csv dictreader in python

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


neuphyte at gmail

Nov 3, 2009, 11:55 PM

Post #1 of 2 (48 views)
Permalink
using csv dictreader in python

Hello all,

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

import csv

r25 = csv.DictReader(open('Report_
25', 'rb'), delimiter=',')

rownum = 1
for row in r25:
# Save header row.
if rownum == 0:
header = row
else:
colnum = 0
for col in row:

This only gets me the following output

{'FieldName1': '4', 'FieldName2': '0.00', 'FieldName3':
'4001433', 'FieldName4': '759'}

1. How do i access the 4, 0.00, ... the values ?
2. How do i compare it with another csv file ?

Thanks in advance
Siva


jspies at sun

Nov 4, 2009, 2:36 AM

Post #2 of 2 (38 views)
Permalink
Re: using csv dictreader in python [In reply to]

On Wed, Nov 04, 2009 at 01:25:16PM +0530, Siva Subramanian wrote:

> This only gets me the following output
>
> {'FieldName1': '4', 'FieldName2': '0.00', 'FieldName3':
> '4001433', 'FieldName4': '759'}
>
> 1. How do i access the 4, 0.00, ... the values ?

>>> a= {'FieldName1': '4', 'FieldName2': '0.00', 'FieldName3': '4001433', 'FieldName4': '759'}
>>> a
{'FieldName4': '759', 'FieldName1': '4', 'FieldName3': '4001433', 'FieldName2': '0.00'}
>>> a['FieldName3']
'4001433'

> 2. How do i compare it with another csv file ?

If you have the values in one file, get the values in the other one
and then compare. I am not sure I understand what is the problem here.

Regards
Johann
--
Johann Spies Telefoon: 021-808 4599
Informasietegnologie, Universiteit van Stellenbosch

"Train up a child in the way he should go: and when he
is old, he will not depart from it." Proverbs 22:6
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.