Can't listdir a file
Package:
zipp
21
Exception Class:
ValueError
Raise code
def exists(self):
return self.at in self.root._name_set()
def iterdir(self):
if not self.is_dir():
raise ValueError("Can't listdir a file")
subs = map(self._next, self.root.namelist())
return filter(self._is_child, subs)
def __str__(self):
return posixpath.join(self.root.filename, self.at)
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/jaraco/zipp/blob/2158b059669a7abfce0a485c647d822a51ca7a9c/zipp.py#L291See also in the other packages (1)
(❌️ No answer)
pipenv/can-t-listdir-a-file/
Ways to fix
Summary: make sure you use a slash at the end of the path your want to iter over:
Code to reproduce (WRONG):
import zipp, io
data = io.BytesIO()
zf = zipp.zipfile.ZipFile(data, 'w')
zf.writestr('fol/file.txt', 'content of a')
p = zipp.Path(zf, 'fol')
print('List of files', list(p.iterdir()))
Working version (Fixed):
import zipp, io
data = io.BytesIO()
zf = zipp.zipfile.ZipFile(data, 'w')
zf.writestr('fol/file.txt', 'content of a')
p = zipp.Path(zf, 'fol/') # <--- HERE IS A FIX WE ADDED SLASH
print('List of files', list(p.iterdir()))
Add a possible fix
Please authorize to post fix