Python "AttributeError: ZipFile Instance Has No Attribute ‘__Exit__"

  • Home /
  • Blog Posts /
  • python "AttributeError: ZipFile instance has no attribute ‘__exit__"

This is actually a very easy error to fix, eventhough off the bat it seems a lot more involved.

You probably have syntax something like this:

with zipfile.ZipFile(wr_zip) as zipfd:
  extract(zipfd, wr_csv, wr_csv)

So instead we will change it to this:

zipfd = zipfile.ZipFile(wr_zip)
extract(zipfd, wr_csv, wr_csv)

The reason this fixes it is because at the moment (Python 2.6/2.7 I believe) the zipfile.ZipFile class has no __exit__ attribute, so it does not work with a `with statement` as other file objects do.