Q&A参考连接 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&…
使用os.path.exists()方法可以直接判断文件是否存在.代码如下:>>> import os>>> os.path.exists(r'C:\1.TXT')False>>> os.path.exists(path)Return True if path refers to an existing path. Returns False for broken symbolic links. On some platforms, this func…