By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,027 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,027 IT Pros & Developers. It's quick & easy.

check file Existing with Python Script

P: 15
Are there any way to check the file existence in Python script.
Apr 23 '20 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 10K+
P: 12,427
Import the os module and use the os.path.isfile(path) function
Apr 23 '20 #2

P: 8
Python provides exists() function which can be used like below.
Expand|Select|Wrap|Line Numbers
  1. import os.path  
  3. if(os.path.exists("/etc/passwd")):  
  5.    print("/etc/passwd exists")
Apr 24 '20 #3

Post your reply

Sign in to post your reply or Sign up for a free account.