python to parse excel file csv format

MRAB google at mrabarnett.plus.com
Wed Dec 3 20:21:25 CET 2008


Jay Jesus Amorin wrote:
> This is how i do it, but it runs with error. Kindly help
> 
> 
> #!/usr/bin/env python
> 
> import csv, sys, os
> filename = (sys.argv[1])
> reader = csv.reader(open(filename, "rb"), delimiter=',', 
> quoting=csv.QUOTE_NONE)
> 
> try:
>         for row in reader:
>                 os.popen("chown row[0] row[1]")
This should be:

     os.popen("chown %s %s" % (row[0], row[1]))

or:

     os.popen("chown %s %s" % tuple(row))

> 
> except csv.Error, e:
You could try adding:

     print e

and perhaps:

     print repr(reader), dir(reader)

here to see what the message was and why the following line raises an 
exception.

>         sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
> 
> 
> ==================================================================
> 
> 
> testserver:~> ./promote2prod.py test.xls
> Traceback (most recent call last):
>   File "./promote2prod.py", line 12, in ?
>     sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
> AttributeError: '_csv.reader' object has no attribute 'line_num'
> 




More information about the Python-list mailing list