'ZipExtFile' object has no attribute 'open'

Question:

I have a file f that i pulled from a url response:

<zipfile.ZipExtFile name='some_data_here.csv' mode='r' compress_type=deflate>

But for some reason i can’t do f.open('some_data_here.csv')

I get an error saying:
'ZipExtFile' object has no attribute 'open'

I’m really confused because isn’t that one of the attributes of ZipExtFile?

Asked By: Raksha

||

Answers:

I’m really confused because isn’t that one of the attributes of ZipExtFile?

A ZipExtFile object is what you get when you call open on a ZipFile:

>>> import zipfile
>>> z = zipfile.ZipFile('arduino-ide_2.0.3_Linux_64bit.zip')
>>> f = z.open('arduino-ide_2.0.3_Linux_64bit/LICENSE.electron.txt')
>>> f
<zipfile.ZipExtFile name='arduino-ide_2.0.3_Linux_64bit/LICENSE.electron.txt' mode='r' compress_type=deflate>

There is no open method on a ZipExtFile because it’s already an open file. You can read or readline from it:

>>> f.readline()
b'Copyright (c) Electron contributorsn'
Answered By: larsks
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.