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
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.
Usage:
If you type
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!