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
相关推荐
向日的葵0061 小时前
langchain的Tools教程(三)
python·langchain·tools
逝水无殇1 小时前
C# 异常处理详解
开发语言·后端·c#
言乐62 小时前
Python实现可运行解密游戏游戏框架
python·游戏·小程序·游戏程序·关卡设计
YUS云生3 小时前
Python学习笔记·第31天:FastAPI入门——路由、路径参数、查询参数与请求体
笔记·python·学习
玖玥拾3 小时前
C# 语言进阶(十五)C# 游戏服务端 MySQL 数据库
服务器·开发语言·网络·数据库·mysql·c#
智写-AI3 小时前
真实有效的免费降英文AI工具服务商
人工智能·python
铅笔侠_小龙虾3 小时前
Rust 学习目录
开发语言·学习·rust
yuhuofei20214 小时前
【Python入门】了解掌握Python中函数的基本使用
python
云泽8084 小时前
从零吃透 C++ 异常:抛出捕获、栈展开、异常重抛与编码规范详解
开发语言·c++·代码规范
灯澜忆梦4 小时前
GO---可见性规则
开发语言·golang