python to parse excel file csv format

MRAB google at mrabarnett.plus.com
Thu Dec 4 16:13:44 CET 2008


Jay Jesus Amorin wrote:
> This is what i have done and its giving me error.
> 
> #!/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:
>     for fmodes,fname in reader:

fmodes and fname are both strings.

>         os.chmod(fname,fmodes)   

os.chmod() expects its second argument to be an int:

           os.chmod(fname, int(fmodes))

> 
> except csv.Error, e:
>     sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
> 
> 
> testserver:~> ./parsecsv.py chown.csv
> Traceback (most recent call last):
>   File "./promote2prod.py", line 10, in ?
>     os.chmod(fname,fmodes)   
> TypeError: an integer is required
> 
> 
> Please help I'm a complete newbie to python.
> 
> Many thanks.
> 



More information about the Python-list mailing list