python to parse excel file csv format

Tino Wildenhain tino at wildenhain.de
Wed Dec 3 15:32:55 EST 2008


MRAB wrote:
> 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))

No, it should really be os.popen(("chown",row[0],row[1]))
or better yet,

for fmodes,fname in reader:
     os.popen(("chown",fmodes,fname))

or even plus better:

for fmodes,fname in reader:
     os.chmod(fname,fmodes)

(Both my examples avoid problems with unquoted filenames)

Regards
Tino
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20081203/b9b8318e/attachment-0001.bin>


More information about the Python-list mailing list