2017-09-27 75 views

回答

3

在創建ZipFile對象,你可以寫:

with zipfile.ZipFile('myzip.zip', 'w') as zip: 
    zip.write('file.py') 
    zip.comment = b'This is my comment' 

文本必須輸入二進制前綴b

https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.comment

如果你的檔案已經存在,你可以也可以使用模式a來附加評論:

with zipfile.ZipFile('myzip.zip', 'a') as zip: 
    zip.comment = b'This is a new comment' 

要設置的評論文件拉鍊,你必須訪問ZipInfo對象像下面,或者用方法from_file創建:

with zipfile.ZipFile('myzip.zip', 'w') as zip: 
    zip.write('file.py') 
    info = zip.getinfo('file.py') 
    info.comment = b'zipped file comment' 
+0

不,我的意思是zipinfo.comment https://開頭的文檔.python.org/3/library/zipfile.html#zipfile.ZipInfo.comment –

+0

但無論如何感謝 –

+0

我的壞,編輯;-) – PRMoureu

相關問題