python判断文件是否存在

复制代码
import os 

test_path ="/Users/yxk/Desktop/test/GrayScale.tif"
if(os.path.exists(test_path)):
    print('文件存在!!!!')
else:
    print("文件不存在!!!!")

结果如下

代码

复制代码
import os 

test_path ="/Users/yxk/Desktop/testA/GrayScale.tif"
if(os.path.exists(test_path)):
    print('文件存在!!!!')
else:
    print("文件不存在!!!!")
相关推荐
用户8356290780519 小时前
无需 Office:Python 批量转换 PPT 为图片
后端·python
日月云棠10 小时前
各版本JDK对比:JDK 25 特性详解
java
markfeng811 小时前
Python+Django+H5+MySQL项目搭建
python·django
用户83071968408211 小时前
Spring Boot 项目中日期处理的最佳实践
java·spring boot
JavaGuide12 小时前
Claude Opus 4.6 真的用不起了!我换成了国产 M2.5,实测真香!!
java·spring·ai·claude code
GinoWi12 小时前
Chapter 2 - Python中的变量和简单的数据类型
python
IT探险家12 小时前
Java 基本数据类型:8 种原始类型 + 数组 + 6 个新手必踩的坑
java
JordanHaidee12 小时前
Python 中 `if x:` 到底在判断什么?
后端·python
花花无缺12 小时前
搞懂new 关键字(构造函数)和 .builder() 模式(建造者模式)创建对象
java
用户9083246027312 小时前
Spring Boot + MyBatis-Plus 多租户实战:从数据隔离到权限控制的完整方案
java·后端