Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6664963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:40:19+00:00 2026-05-26T02:40:19+00:00

Based on the with statement The context manager’s __exit__() is loaded for later use.

  • 0

Based on the with statement

  • The context manager’s __exit__() is loaded for later use.
  • The context manager’s __enter__() method is invoked.

I have seen one of the with usage with zipfile

Question>
I have checked the source code of zipfile located here:

/usr/lib/python2.6/zipfile.py

I don’t know where the __enter__ and __exit__ functions are defined?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:40:19+00:00Added an answer on May 26, 2026 at 2:40 am

    I’ve added this as another answer because it is generally not an answer to initial question. However, it can help to fix your problem.

    class MyZipFile(zipfile.ZipFile): # Create class based on zipfile.ZipFile
      def __init__(file, mode='r'): # Initial part of our module
        zipfile.ZipFile.__init__(file, mode) # Create ZipFile object
    
      def __enter__(self): # On entering...
        return(self) # Return object created in __init__ part
      def __exit__(self, exc_type, exc_val, exc_tb): # On exiting...
        self.close() # Use close method of zipfile.ZipFile
    

    Usage:

    with MyZipFile('new.zip', 'w') as tempzip: # Use content manager of MyZipFile
      tempzip.write('sbdtools.py') # Write file to our archive
    

    If you type

    help(MyZipFile)
    

    you can see all methods of original zipfile.ZipFile and your own methods: init, enter and exit. You can add another own functions if you want.
    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have a running average column in the SELECT statement based
I have a linq statement that searches a number of fields based on user
I am executing If statement based on some vales but Nunit executes all statements
How can I do an if statement based on the value of a mysql
I'm programming a simple text-based RPG using a switch statement for a game loop.
I have several instances where that a section of legacy sql statements is based
I'm trying to use the IE specific conditional statements to alter class settings based
Why does INDEX creation statement have UNIQUE argument? As I understand, the non-clustered index
I have tried to use this code in VS2008 (and may have included too
I have the following Execution statement which creates a table (using data from another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.