Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python zipfile module creates multiple files with same name

I have following code in python:

>>> import zipfile
>>> zip = zipfile.ZipFile('abc.zip', 'w')
>>> zip.writestr('myfile', 'This is sample text')
>>> zip.writestr('myfile', 'This is sample text')
>>> zip.close()

This creates an archive with two files having exactly same name and path.

Why is this?

enter image description here

like image 427
Kshitiz Sharma Avatar asked Mar 03 '14 10:03

Kshitiz Sharma


1 Answers

This is allowed by Zip and some other archive formats, like Tar, and even addressed by the Python API:

Note: The open(), read() and extract() methods can take a filename or a ZipInfo object. You will appreciate this when trying to read a ZIP file that contains members with duplicate names.

like image 95
bereal Avatar answered Oct 15 '22 01:10

bereal