os模块中的os.path.exists()
方法用于检验文件是否存在。
- 判断文件是否存在
import os
os.path.exists(test_file.txt)
#True
os.path.exists(no_exist_file.txt)
#False
- 判断文件夹是否存在
import os
os.path.exists(test_dir)
#True
os.path.exists(no_exist_dir)
#False
os模块中的os.path.exists()
方法用于检验文件是否存在。
import os
os.path.exists(test_file.txt)
#True
os.path.exists(no_exist_file.txt)
#False
import os
os.path.exists(test_dir)
#True
os.path.exists(no_exist_dir)
#False