Python3 zipfile writestr,用户警告:名称重复

时间:2018-12-25 02:57:51

标签: python python-3.x

对于每次修改,在已修改的文件数上添加一个

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'

0 个答案:

没有答案