Reading a CSV file into a list of dictionaries
Laurent RAHUEL
laurent.rahuel at net-ng.com
Tue Jun 7 18:02:53 EDT 2005
John Machin wrote:
> Laurent RAHUEL wrote:
>> RFQ wrote:
>>
>>
>>>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,...
>>
>>
>> This is NOT a CSV file. A CSV file would be :
>>
>> PNumber,Contractor,Architect,...
>> 2056,XYZ Contracting,ABC Architects,...
>>
>
> CSV is an acronym for "Comma-Separated Values". It does not imply
> anything about the contents of the fields. The OP's file *is* a CSV
> file. Yes, the contents do represent an unusual application of the CSV
> format -- however a bus full of parcels instead of people is still a bus.
I thought you knew the number of cols and what you should expect in each.
Then it sounded pretty easy to build a list of dictionaries. If you don't
know what you're supposed to find in your file and how this file is
structured I guess you don't know what you are doing.
>
>> Then, you could use the built-in CSV module of recent python versions.
>
> Python is a case-sensitive language. The name of the module is "csv".
> The OP could use the csv module with his data.
Damn, that's why I always see those annoynig import errors.
I just wanted to help, maybe you're to much case-sensitive.
Regards,
Laurent.
More information about the Python-list
mailing list