Home > OS >  'ZipExtFile' object has no attribute 'open'
'ZipExtFile' object has no attribute 'open'

Time:01-27

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?

CodePudding user response:

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'
  • Related