Message322272
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. |
|
Date |
User |
Action |
Args |
2018-07-23 23:17:13 | mkleehammer | set | recipients:
+ mkleehammer |
2018-07-23 23:17:13 | mkleehammer | set | messageid: <1532387833.75.0.56676864532.issue34202@psf.upfronthosting.co.za> |
2018-07-23 23:17:13 | mkleehammer | link | issue34202 messages |
2018-07-23 23:17:13 | mkleehammer | create | |
|