Python——Bug解决:文件存在但os.path.exists或os.path.isfile返回false

问题

  • python脚本访问路径,前一级路径存在,但文件不存在:
bash 复制代码
(Pdb) os.path.isfile(f"/mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is/adapter_model.bin")
False
(Pdb) os.path.isfile(f"/mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is")
True
  • 命令行ls看,是存在的:
bash 复制代码
>>> ls /mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is/adapter_model.bin
/mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is/adapter_model.bin

可能问题原因及解决方法

1.

2.

  • 给权限即可。

反转

  • 但我发现这个权限也没问题,而且最重要的是我发现它只是个软链接,因此这个文件不存在极可能是由于原文件不存在了
bash 复制代码
>>> ls -l /mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is/adapter_model.bin
lrwxrwxrwx 1 gaohongzhi gaohongzhi 179 Nov  2 15:38 /mnt/flan_t5_large-adversarial_qa_dbert_tell_what_it_is/adapter_model.bin -> ../../../../../../.cache/huggingface/hub/models--lorahub--flan_t5_large-adversarial_qa_dbert_tell_what_it_is/blobs/37a8d9c6732bfab95b168e90e02363d8a254ad1ac208fc32f9e61b2c693f5230
  • 果然这玩意就什么都不是!所以还是文件有问题导致的!
bash 复制代码
>>> ls -l /.cache/huggingface/hub/models--lorahub--flan_t5_large-adversarial_qa_dbert_tell_what_it_is/blobs/37a8d9c6732bfab95b168e90e02363d8a254ad1ac208fc32f9e61b2c693f5230
相关推荐
c++之路1 小时前
CMake 系列教程(二):基础命令详解
开发语言·c++
winfredzhang1 小时前
用 MediaPipe 手势数字识别一键打开下载夹里的图片(Python + OpenCV 实战)
人工智能·python·opencv·google·mediapipe
南境十里·墨染春水5 小时前
C++ 工厂模式:从入门到进阶,彻底掌握对象创建的艺术
开发语言·c++·算法
某人辛木6 小时前
Web自动化测试
前端·python·pycharm·pytest
C+++Python6 小时前
详细介绍一下Java泛型的通配符
java·windows·python
JosieBook7 小时前
【数据库】时序预测能力的分级进化:TimechoAI如何让每一类用户都能精准预见未来
java·开发语言·数据库
加号37 小时前
【C#】 文件与目录管理:创建、删除操作的技术解析
开发语言·c#
小帅热爱难回头7 小时前
编写Skill生成AI落地项目系统架构
python
diving deep7 小时前
脚本速览-python
开发语言·python
一生了无挂7 小时前
Java处理JSON技巧教学(从基础到高阶实战全覆盖)
java·开发语言·json