#๐Ÿ”’ zipfile not being created (?)

8 messages ยท Page 1 of 1 (latest)

rose pine
#

Given this code:

import io
import zipfile

zipbytes = io.BytesIO()
zip = zipfile.ZipFile(zipbytes, 'w', zipfile.ZIP_DEFLATED, False)

and running the program, i get this error:

Exception ignored in: <function ZipFile.__del__ at 0x101244220>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/zipfile.py", line 1874, in __del__
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/zipfile.py", line 1891, in close
ValueError: I/O operation on closed file.

the error appears, when the code tries initialising the zip variable .
But it appears, that the error is ignored and the rest of the program executes just fine, HOWEVER the zipfile is not created at the end, which led me to assume, that this error is the reason it is not created. I could not find any reference of it on the internet or any relation of it to the zipfile library. How can i fix this?

winged roverBOT
#

@rose pine

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

still zodiac
#

HOWEVER the zipfile is not created at the end
What do you mean? I don't see you creating any files here - you're using a BytesIO.

rose pine
#

I am so sorry, in the process of reformatting the code i accidentally removed the actually zip file creation code, and the appearance of the error confused me. Now that the code responsible for creating the zip file is back, everything is working as expected

#

!close

winged roverBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.