Python Programming - Reading and Writing Files - Discussion

Discussion Forum : Reading and Writing Files - General Questions (Q.No. 10)
10.
How can you check if a file named "data.txt" exists in a directory using Python?
file_exists("data.txt")
if not exists("data.txt"):
os.path.exists("data.txt")
if "data.txt" in os.listdir():
Answer: Option
Explanation:
The os.path.exists() function checks if a file exists in a directory.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.