Message from discussion
Reading a CSV file into a list of dictionaries
Path: g2news1.google.com!news4.google.com!news.glorb.com!newsgate.cistron.nl!transit4.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path: <python-python-l...@m.gmane.org>
X-Original-To: python-l...@python.org
Delivered-To: python-l...@bag.python.org
X-Spam-Status: OK 0.000
X-Injected-Via-Gmane: http://gmane.org/
To: python-l...@python.org
From: "GMane Python" <s_david_r...@hotmail.com>
Subject: Re: Reading a CSV file into a list of dictionaries
Date: Tue, 7 Jun 2005 12:34:08 -0400
References: <1118078038.100136.56630@f14g2000cwb.googlegroups.com>
X-Gmane-NNTP-Posting-Host: 65.220.66.67
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Sender: news <n...@sea.gmane.org>
X-BeenThere: python-l...@python.org
X-Mailman-Version: 2.1.6
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list>
List-Post: <mailto:python-l...@python.org>
List-Help: <mailto:python-list-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-requ...@python.org?subject=subscribe>
Newsgroups: comp.lang.python
Message-ID: <mailman.91.1118162319.10512.python-list@python.org>
Lines: 36
NNTP-Posting-Host: 194.109.207.14
X-Trace: 1118162320 news.xs4all.nl 49265 [::ffff:194.109.207.14]:39617
X-Complaints-To: abuse@xs4all.nl
Sounds like you want to use the ConfigObject module.
http://www.voidspace.org.uk/python/modules.shtml#configobj
-dave
"RFQ" <rfque...@gmail.com> wrote in message
news:1118078038.100136.56630@f14g2000cwb.googlegroups.com...
> Hi, I'm struggling here to do the following with any success:
>
> I have a comma delimited file where each line in the file is something
> like:
>
> PNumber,3056,Contractor,XYZ Contracting,Architect,ABC Architects,...
>
> So each line is intended to be: key1,value1,key2,value2,key3,value3...
> and each line is to be variable in length (although it will have to be
> an even number of records so that each key has a value).
>
> I want to read in this csv file and parse it into a list of
> dictionaries. So each record in the list is a dictionary:
>
> {"PNumber":"3056","Contractor":"XYZ Contracting", ... }
>
> I have no problem reading in the CSV file to a list and splitting each
> line in the file into its comma separated values. But I can't figure
> out how to parse each resulting list into a dictionary.
>
> Any help on this?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>