Python Pathlib找到了一个文件,但然后放松了吗?
我需要找到一个具有特定命名法的 Excel 文件,但我收到一个奇怪的错误:
ppp = pathlib.Path('A:\\bsolute\path_to\dir_being_searched').glob('**/*edit.xlsx')
for iii in ppp:
print(iii.absolute())
然后,这会返回一个具有正确命名法的文件的绝对路径(但不是我想要的),然后出现错误:
FileNotFoundError Traceback (most recent call last)
Input In [19], in <cell line: 2>()
1 ppp = pathlib.Path('A:\\bsolute\path_to\dir_being_searched').glob('**/*edit.xlsx')
----> 2 for iii in ppp:
3 print(iii.absolute())
etc.
File C:\Anaconda3.7\envs\env_name\lib\pathlib.py:558, in _WildcardSelector._select_from(self, parent_path, is_dir, exists, scandir)
556 def _select_from(self, parent_path, is_dir, exists, scandir):
557 try:
--> 558 with scandir(parent_path) as scandir_it:
559 entries = list(scandir_it)
560 for entry in entries:
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'A:\\bsolute\\path_to\\dir_being_searched\\more\\dirs'
我不是当然如何,但在我看来,就像它找到一个带有 glob 的文件,然后当它通过生成器时却无法再次找到它。我使用的是 Python 3.9.10,这发生在 Windows 10 上的 jupyter 笔记本中。
I need to find an excel file with certain nomenclature but I'm receiving an odd error:
ppp = pathlib.Path('A:\\bsolute\path_to\dir_being_searched').glob('**/*edit.xlsx')
for iii in ppp:
print(iii.absolute())
This then returns one absolute path to a file (but not the one I want) with the right nomenclature and then errors out with:
FileNotFoundError Traceback (most recent call last)
Input In [19], in <cell line: 2>()
1 ppp = pathlib.Path('A:\\bsolute\path_to\dir_being_searched').glob('**/*edit.xlsx')
----> 2 for iii in ppp:
3 print(iii.absolute())
etc.
File C:\Anaconda3.7\envs\env_name\lib\pathlib.py:558, in _WildcardSelector._select_from(self, parent_path, is_dir, exists, scandir)
556 def _select_from(self, parent_path, is_dir, exists, scandir):
557 try:
--> 558 with scandir(parent_path) as scandir_it:
559 entries = list(scandir_it)
560 for entry in entries:
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'A:\\bsolute\\path_to\\dir_being_searched\\more\\dirs'
I'm not sure how, but it looks to me like its finding a file with the glob and then failing to find it again when it goes through the generator. I'm using Python 3.9.10 and this is happening in a jupyter notebook on Windows 10.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论