python to parse excel file csv format

Jay Jesus Amorin jay.amorin at gmail.com
Wed Dec 3 13:49:21 EST 2008


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]")

except csv.Error, e:
        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'



On Thu, Dec 4, 2008 at 2:25 AM, Jay Jesus Amorin <jay.amorin at gmail.com>wrote:

> Hi all,
>
> Can anyone please help me. i need to parse the content of my csv excel file
> and run the unix command chown.
>
> test.csv:
>
> "/dev/trunk/admin/sql/ADBPOS_CMSI_NATIONALITY.syn",814
> "/dev/trunk/bin/ADBPOSCMSDICED.ctl",405
> "/dev/trunk/discoverer/ADBPOS_BUSINESS_AREA.eex",215
>
>
> Please help me parse the csv file and run chown $csvfile_secondcolumn
> $csvfile_firstcolumn.
>
> Here's how i want to run it.
>
> ./parsecsv.py test.csv
>
>
> Many thanks.
>
>
> Jay
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081204/8f29763c/attachment-0001.html>


More information about the Python-list mailing list