Skip to content

ZipStore arguments: 'w' vs 'x' #2683

Discussion options

You must be logged in to vote

Unlike most stores, the ZipStore obeys normal python file-opening semantics. Just like a python file (or zipfile), , the file is automatically closed when the object is garbage collected, but you're not in control of when that happens (and it can be dependent on how your script/ package is structured) so for certain usage patterns it can lead to unpredictable numbers of files being open at once.

Also like python files/ zipfiles, there's a .close() method to explicitly close it (which is what the with statement does implicitly as soon as you leave the block) - that seems to be what the examples use. But in general using it directly is discouraged because if an exception happens before the …

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by jhamman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
documentation Improvements to the documentation
2 participants
Converted from issue

This discussion was converted from issue #1057 on January 10, 2025 06:03.