read Zipfile
sityee kong
skong1 at gmail.com
Mon Nov 2 18:39:07 EST 2009
Hi all,
I'm writing a program to manipulate data in 3 different kind of format,
there are GZIP, cvs/txt, or ZIP file.
Here is part of my program to open these 3 kind formats of file,
if (option==1):
file=gzip.GzipFile(sys.argv[1],"r")
elif (option==2):
file=open(sys.argv[1],"r")
elif (option==3):
archive=zipfile.ZipFile(sys.argv[1],"r")
I have no problem with opening GZIP or cvs/txt file.
However for the ZIP file, let says the ZIP file contains only one member,
>>> archive.namelist()
['CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv']
I would like to open the csv file with folowwing command,
file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r")
But it turned out error,
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: ZipFile instance has no attribute 'open'
Do you know the way to open an file from a ZIP archive, but not reading them
all into memory. I would manipulate each line using "for line in file:"
Hope my contents do make sense.
Thanks,
phoebe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091102/5e2a41d5/attachment.html>
More information about the Python-list
mailing list