python如何判断图片路径是否存在
发布时间:2021-04-11 编辑:jiaochengji.com
教程集为您提供python如何判断图片路径是否存在等资源,欢迎您收藏本站,我们将为您提供最新的python如何判断图片路径是否存在资源
1、在向文件夹中保存数据前,先判断该文件夹(路径)是否存在。
save_path = '/root/.../image/result' if not os.path.exists(save_path): os.makedirs(save_path)
相关推荐:《Python入门教程》
本来路径里只有到image文件夹的,执行完后会自动在image下创建result文件夹。
2、在打开某些图片时,可以先判断该图片的路径是否存在。
if img == 'target7.jpg': img_path = os.path.join(dir_path, img) if imghdr.what(img_path): # 判断是否能打开 target_img = Image.open(img_path) target_img.save(os.path.join(root, 'trainB/{}_B.jpg'.format(count 6)))
您可能感兴趣的文章:
python如何判断图片路径是否存在
python的假如路径不存在如何写
js判断图片是否被缓存的一例代码
python如何缩小图像
python怎么判断txt文件是否存在
python怎么制作游戏脚本
帝国cms内容页判断标题图片是否存在的方法
python如何用if判断文件夹是否存在
HTML5 Canvas调用手机拍照功能实现图片上传功能(图文详解下篇)
php抓取远程图片到本地保存的方法
上一篇:python 如何引用变量
下一篇:python 怎么调用js
[关闭]