Can I check the existence of the file without using try-catch?

Asked 2 years ago, Updated 2 years ago, 44 views

Can I check the existence of the file without using try-catch in Python?

python file

2022-09-22 13:24

1 Answers

Write os.path.isfile. isfile() returns 1 if the file exists.

import os.path
os.path.isfile(fname) 


2022-09-22 13:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.