exists() 判斷文件或路徑是否存在。
exists() 接收兩個參數(shù),第一個為文件或路徑,第二個為檢測類型,文件或目錄。
以下是 exists() 的語法:
exists(path, type='dir')
● path [str]:文件或路徑。
● type [str]:dir:檢測目錄是否存在,file:檢測文件是否存在。
返回布爾類型。
以下展示了使用 exists() 的實例:
from kyger.utility import exists print(exists('static/404')) # 判斷目錄是否存在 print(exists('static/kgcms.json', type='file')) # 判斷文件是否存在
以上實例運行后輸出的結果為:
True False