「Python」os.path.exists関数の使い方

説明
os.path.exists関数を使用して、フォルダとファイルの存在チェックを行います。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import os
print(os.path.exists('test.csv'))
print(os.path.exists('user.csv'))
#フォルダの存在チェック
print(os.path.exists('test'))
print(os.path.exists('user'))
import os print(os.path.exists('test.csv')) print(os.path.exists('user.csv')) #フォルダの存在チェック print(os.path.exists('test')) print(os.path.exists('user'))
import os
 
print(os.path.exists('test.csv'))

print(os.path.exists('user.csv'))

#フォルダの存在チェック 
print(os.path.exists('test'))
 
print(os.path.exists('user'))

実行結果
True
False
True
False

Python

Posted by arkgame