python如何使用 os.path.exists()--Learning from stackoverflow
2015-04-23 20:48
435 查看
Q&A参考连接
Problem:IOError: [Errno 2] No such file or directory。
os.path.exists() 如果目录不存在,会返回一个0值。
所以,如果你如下使用该函数,会得到 Problem 中描述的错误,而且错误会定位在其他地方:
正确的使用方式如下:
Problem:IOError: [Errno 2] No such file or directory。
os.path.exists() 如果目录不存在,会返回一个0值。
所以,如果你如下使用该函数,会得到 Problem 中描述的错误,而且错误会定位在其他地方:
import os try: os.path.exists("E:/Contact") #Check if dir exist except: os.mkdir("E:/Contact") #if not, create
正确的使用方式如下:
if not os.path.exists("E:/Contact"): os.mkdir("E:/Contact")
相关文章推荐
- python如何使用 os.path.exists()--Learning from stackoverflow 分类: python 2015-04-23 20:48 139人阅读 评论(0) 收藏
- Python学习18:os标准库模块使用(二),path模块使用
- Python标准库os.path包、glob包使用实例
- 如何使用Python 打开exel等各种文件或者应用,就用:os.startfile
- python中的os.path.dirname(__file__)的使用
- Comprehensive learning path – Data Science in Python深入学习路径-使用python数据中学习
- python中os.path.dirname(__file__)和sys.path[0]使用
- Python标准库os.path包、glob包使用实例
- python使用os.walk和os.path.join来遍历文件夹的文件(包括子文件夹下的文件)
- python使用os.walk和os.path.join来遍历文件夹的文件(包括子文件夹下的文件)
- Learning by doing 系列文章(之一)如何在 Python 中使用 epoll ?
- 如何使用PathFileExists
- static_cast dynamic_cast reinterpret_cast 使用准则 guide from stackoverflow
- Python_API_os.path_exists_待填充
- python中os.path.dirname(__file__)的使用
- python中os.path.dirname(__file__)的使用
- python中os.path.dirname(__file__)的使用
- Python代码中os.path常见属性的相关介绍 from 路人甲
- Python代码中os.path常见属性的相关介绍 from 路人甲
- python中的os.path.dirname(__file__)的使用