[New-bugs-announce] [issue34202] 3.6 ZipFile fails with Path
Michael Kleehammer
report at bugs.python.org
Mon Jul 23 19:17:13 EDT 2018
New submission from Michael Kleehammer <michael at kleehammer.com>:
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 <report at bugs.python.org>
<https://bugs.python.org/issue34202>
_______________________________________
More information about the New-bugs-announce
mailing list