Getting MemoryError when opening large Zip file around 1.5GB in python 3.7.4

0

I am running the following code to caluclate CRC32 of ZIP file

buf = open("C:\\users\\Raj\\temp\\ZIPs\\XXX.ZIP",'rb').read()

MemoryError

If i restart the machines it works fine and after running this command for multiple times i am getting the same error

This is the code i am using for caluclating CRC of ZIP file more than a 1.5 GB

zip_file=C:\\users\\Raj\\temp\\ZIPs\\XXX.ZIP"
buf = open(zip_file,'rb').read()
buf = (binascii.crc32(buf) & 0xFFFFFFFF)
(open(zip_file,'rb')).close()
python
asked on Stack Overflow Oct 17, 2019 by Rajashekhara • edited Oct 17, 2019 by shaik moeed

1 Answer

0

You are not closing the opened zip file. Try this:

zip_file="C:\\users\\Raj\\temp\\ZIPs\\XXX.ZIP"
with open(zip_file,'rb') as handle:
    buf = handle.read()
    buf = (binascii.crc32(buf) & 0xFFFFFFFF)
answered on Stack Overflow Oct 17, 2019 by gb_stackoverflow

User contributions licensed under CC BY-SA 3.0