Networking-Forums.com

Professional Discussions => Programming Goodies and Software-Defined Networking => Topic started by: nikolaymartin on April 23, 2020, 09:50:22 AM

Title: check file Existing with Python Script
Post by: nikolaymartin on April 23, 2020, 09:50:22 AM
Are there any way to check the file existence in Python script.
Title: Re: check file Existing with Python Script
Post by: Otanx on April 23, 2020, 11:17:22 AM
There is a ".exists" function that will return True. Off the top of my head...

import os
print(os.file.exists("myfile.txt"))

Will print True if file exists, and False if it is missing.

Code may not be 100% but should be close

-Otanx

Title: Re: check file Existing with Python Script
Post by: edizgeorgi on April 24, 2020, 05:30:37 AM
Python provides exists() function which can be used like below. Look https://www.networking-forums.com/programming-goodies-and-software-defined-networking/check-file-existing-with-python-script for more information. 

import os.path 

if(os.path.exists("/etc/passwd")): 

   print("/etc/passwd exists")