Problem reading csv files

Chris cwitts at gmail.com
Fri Jan 4 08:27:55 CET 2008


On Jan 4, 6:24 am, Ramashish Baranwal <ramashish.li... at gmail.com>
wrote:
> Hi,
>
> I am trying to read a csv file using csv.reader. The file is created
> using Open Office and saved in Excel format.
>
> import csv
>
> reader = csv.reader(open('test.xls'))
> for row in reader:
>     print row
>
> It however throws the exception _csv.Error:
> <class '_csv.Error'>: line contains NULL byte
>
> Any idea whats going wrong here?
>
> Thanks in advance,
> Ram

XLS != CSV
XLS is M$'s format for spreadsheets whereas CSV is essentially a text
document with comma-delimited fields.  If you open it up in OpenOffice
and go File -> Save As then in the 'Save as type:' drop-down list
select 'Text CSV (.csv)' and ofc change your code to point to the new
file.

If you want to retain it in XLS Format and rather parse that, take a
look at 'xlrd' and 'pyExcelerator'



More information about the Python-list mailing list