I'm trying to unzip a 8gb csv file with a machine 8gb RAM. This is my implementation, using python 3.6:
def extract_to(zippath, dest):
with zipfile.ZipFile(zippath, mode='r') as z:
for member in z.namelist():
filename = Path(member).basename()
# skip directories
if not filename:
continue
source = z.open(member)
target = open(dest / filename, "wb")
with source, target:
shutil.copyfileobj(source, target)
Unfortunately, it produces the following error:
Traceback (most recent call last):
File "download_data.py", line 31, in extract_to
shutil.copyfileobj(source, target)
File "/home/user/anaconda3/lib/python3.6/shutil.py", line 82, in copyfileobj
fdst.write(buf)
OSError: [Errno 28] No space left on device
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "download_data.py", line 56, in <module>
main()
File "download_data.py", line 49, in main
download_and_extract_zip(train, RAW_DATA_DIR)
File "download_data.py", line 37, in download_and_extract_zip
extract_to(tmppath, dest)
File "download_data.py", line 31, in extract_to
shutil.copyfileobj(source, target)
OSError: [Errno 28] No space left on device
How can I handle this situation? Thanks.