python里面判断文件夹或者文件的路径是否存在
第一种方法、os这个库里的os.path.exists()函数提供了这种用法,具体用法如下
import os
import time
time_start = time.time()
file_path = "/home/hjxu/PycharmProjects/01_cats_vs_dogs/111.jpg"
if os.path.exists(file_path):
print "yes"
else:
print("" file_path ""+ file_path + "" Not found"")
time_end = time.time()
print (time_end - time_start) #"0.00031876"第二种方法、tensorflow也包含了这个功能
主要是tensorflow.python.platform 里面的gfile函数,废话不多说,直接上代码
import time
from tensorflow.python.platform import gfile
if not gfile.Exists(file_path): #判断文件和文件夹是否存在
print("Image directory "" + file_path + "" not found.")
time_end = time.time()
print (time_end - time_start) #0.0003309249声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇: python中plt.imshow(img)显示不了图片
- 下一篇:没有了
