今天正在尝试制作一个能够切割图片的Python脚本,但是每次运行都会出现FileNotFoundError: [Errno 2] No such file or directory: 这样的错报,但是文件正常运行。
__mod_path = os.path.dirname(os.path.abspath(__file__)) __output_path = os.path.join(__mod_path, "output\")
仔细思考了一下才想起,这样的话指定的文件夹可能不存在,需要再创建一个文件夹。
因此加入一段检查文件夹。
__mod_path = os.path.dirname(os.path.abspath(__file__))
__output_path = os.path.join(__mod_path, "output\")
if os.path.exists(__output_path):
pass
else:
os.mkdir(__output_path)
现在不再错报或者以错误的运行方式继续了。


![Python遇到FileNotFoundError: [Errno 2] No such file or directory: \xxx\xxx... Python遇到FileNotFoundError: [Errno 2] No such file or directory: \xxx\xxx...](http://www.mshxw.com/aiimages/31/977796.png)
