Question: PYTHON: Check if file exists: This code will determine if a file exist or not on the defaultdirectory: import os.path filename = input(What test file

PYTHON: Check if file exists:

This code will determine if a file exist or not on the defaultdirectory:

import os.path
filename = input("What test file to open? ")
if os.path.isfile(filename):
print ("File exist")
else:
print ("File not found")

Use the "Try" and "Except" exception to write the same code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To use the try and except exception to check if a file exists you can use the following co... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!