Raksha
Raksha

Reputation: 1699

'ZipExtFile' object has no attribute 'open'

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?

Upvotes: 0

Views: 367

Answers (1)

larsks
larsks

Reputation: 311713

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 contributors\n'

Upvotes: 2

Related Questions