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
相关推荐
南境十里·墨染春水3 小时前
C++传记(面向对象)虚析构函数 纯虚函数 抽象类 final、override关键字
开发语言·c++·笔记·算法
无巧不成书02183 小时前
30分钟入门Java:从历史到Hello World的小白指南
java·开发语言
2301_797172753 小时前
基于C++的游戏引擎开发
开发语言·c++·算法
比昨天多敲两行4 小时前
C++ 二叉搜索树
开发语言·c++·算法
Birdy_x4 小时前
接口自动化项目实战(1):requests请求封装
开发语言·前端·python
我爱学习好爱好爱5 小时前
Ansible 常用模块详解:lineinfile、replace、get_url实战
linux·python·ansible
海海不瞌睡(捏捏王子)5 小时前
C++ 知识点概要
开发语言·c++
桌面运维家5 小时前
VLAN配置进阶:抑制广播风暴,提升网络效率
开发语言·网络·php
一轮弯弯的明月6 小时前
Python基础-速通秘籍(下)
开发语言·笔记·python·学习
西西学代码6 小时前
Flutter---回调函数
开发语言·javascript·flutter