python "AttributeError: ZipFile instance has no attribute ‘__exit__"

0 min read 82 words

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.

Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags