From: Chris Rebert on
On Mon, Nov 2, 2009 at 4:39 PM, sityee kong <skong1(a)gmail.com> wrote:
<snip>
> 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'

ZipFile.open(name[, mode[, pwd]])
[...]
New in version 2.6.

Would your Python version happen to be pre-2.6?

Cheers,
Chris
--
http://blog.rebertia.com
From: Tim Chase on
>> 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'
>
> ZipFile.open(name[, mode[, pwd]])
> [...]
> New in version 2.6.
>
> Would your Python version happen to be pre-2.6?

FWIW, you can use the 2.6 zipfile.py as far back as 2.4 by just
copying it into your project directory. I had a similar issue in
2.4 (wanted the iterator provided by 2.6's open() call) and
Gabriel suggested trying to just copy in the 2.6 version into my
project directory. Worked for me(tm).

-tkc


From: Gabriel Genellina on
En Mon, 02 Nov 2009 20:39:07 -0300, sityee kong <skong1(a)gmail.com>
escribi�:

> 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:"

open was added to the ZipFile class in Python 2.6; which version are you
using?
I think you can backport the 2.6 version onto 2.5 with little or no effort.
http://docs.python.org/library/zipfile.html#zipfile.ZipFile.open

> Hope my contents do make sense.

Yes, it was clear to me.

--
Gabriel Genellina

From: Chris Rebert on
> On Mon, Nov 2, 2009 at 5:02 PM, Tim Chase <python.list(a)tim.thechases.com>
> wrote:
>>>> 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'
>>>
>>> ZipFile.open(name[, mode[, pwd]])
>>> [...]
>>>    New in version 2.6.
>>>
>>> Would your Python version happen to be pre-2.6?
>>
>> FWIW, you can use the 2.6 zipfile.py as far back as 2.4 by just copying it
>> into your project directory.  I had a similar issue in 2.4 (wanted the
>> iterator provided by 2.6's open() call) and Gabriel suggested trying to just
>> copy in the 2.6 version into my project directory.  Worked for me(tm).

On Mon, Nov 2, 2009 at 5:28 PM, sityee kong <skong1(a)gmail.com> wrote:
> Hi all, yes, im using python 2.4.
>
> I would like to know how does python 2.4 work for my case w/o the new added
> feature in 2.6? Do you guys know?

Looks like you'd have to use the more primitive .read() method:
http://docs.python.org/library/zipfile.html#zipfile.ZipFile.read

Also, please avoid top-posting in the future.

Cheers,
Chris
--
http://blog.rebertia.com
From: Tim Chase on
> I would like to know how does python 2.4 work for my case w/o the new added
> feature in 2.6? Do you guys know?

You can just grab the zipfile.py file from within the 2.6
distribution[1] and dump it in your project folder. Python
should find it before it finds the 2.4 version in the
$PYTHONPATH. While you can also overwrite the older stock
version in the $PYTHON_LIB_DIR directory, I recommend against it.

-tkc
(for future reference, please don't top-post)


[1]
http://svn.python.org/projects/python/trunk/Lib/zipfile.py