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
相关推荐
WenGyyyL7 分钟前
ColBERT论文研读——NLP(IR)里程碑之作
人工智能·python·语言模型·自然语言处理
lly2024068 分钟前
SOAP 简介
开发语言
lxy-up11 分钟前
RAG--切片策略
python
ricky_fan18 分钟前
(OpenAI)Codex 安装、部署使用方式
python·macos·conda·vim
小王不爱笑13219 分钟前
Java 对象拷贝(浅拷贝 / 深拷贝)
java·开发语言·python
Flittly30 分钟前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(9)Agent Teams (智能体团队)
python·agent
ℳ๓₯㎕.空城旧梦39 分钟前
C++中的解释器模式
开发语言·c++·算法
DevnullCoffe1 小时前
Open Claw × 跨境电商:5个最有价值的 AI Agent 应用场景深度拆解
python·api
JdayStudy1 小时前
SIR 网络传播仿真软件说明书
开发语言·网络·php
有点傻的小可爱1 小时前
【MATLAB】新安装并口如何实现能通过PTB启用?
开发语言·windows·经验分享·matlab