对于每次修改,在已修改的文件数上添加一个
In [1]: import zipfile
In [2]: with zipfile.ZipFile('demo.zip', 'a') as z:
...: files = z.namelist()
...: print(files)
...: i = z.getinfo('1.txt')
...: z.writestr(i, 'test')
...:
...:
['1.txt', '__MACOSX/', '__MACOSX/._1.txt']
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/zipfile.py:1355: UserWarning: Duplicate name: '1.txt'
return self._open_to_write(zinfo, force_zip64=force_zip64)
In [3]: z = zipfile.ZipFile('demo.zip', 'r')
In [4]: print(z.namelist())
['1.txt', '__MACOSX/', '__MACOSX/._1.txt', '1.txt']
修改后,z.namelist()中有两个“ 1.txt”, 但是当我提取demo.zip时,只有一个'1.txt'