Author mkleehammer
Recipients mkleehammer
Date 2018-07-23.23:17:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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('')
    zf = zipfile.ZipFile(path, 'w')
    zf.writestr('test.txt', 'Hello, Sailor!')

On macOS I'm getting this error:

Traceback (most recent call last):
  File "", line 7, in <module>
    zf.writestr('test.txt', 'Hello, Sailor!')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/", line 1644, in writestr
    with, mode='w') as dest:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/", 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/", line 1461, in _open_to_write
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/", 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:13mkleehammersetrecipients: + mkleehammer
2018-07-23 23:17:13mkleehammersetmessageid: <>
2018-07-23 23:17:13mkleehammerlinkissue34202 messages
2018-07-23 23:17:13mkleehammercreate