New submission from Michael Kleehammer <[email protected]>:
ZipFile is documented to accept "path-like" objects but is failing when I try
to create one. I've distilled it down to this small test:
import zipfile
from pathlib import Path
path = Path('test.zip')
zf = zipfile.ZipFile(path, 'w')
zf.writestr('test.txt', 'Hello, Sailor!')
zf.close()
On macOS I'm getting this error:
Traceback (most recent call last):
File "test.py", line 7, in <module>
zf.writestr('test.txt', 'Hello, Sailor!')
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/zipfile.py",
line 1644, in writestr
with self.open(zinfo, mode='w') as dest:
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/zipfile.py",
line 1348, in open
return self._open_to_write(zinfo, force_zip64=force_zip64)
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/zipfile.py",
line 1461, in _open_to_write
self.fp.write(zinfo.FileHeader(zip64))
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/zipfile.py",
line 721, in write
n = self.fp.write(data)
AttributeError: 'PosixPath' object has no attribute 'write'
Using str(path) works fine.
----------
components: Library (Lib)
messages: 322272
nosy: mkleehammer
priority: normal
severity: normal
status: open
title: 3.6 ZipFile fails with Path
type: behavior
versions: Python 3.6
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34202>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com