It seems strange to me that
with open(file, 'r')
can report
FileNotFoundError: [Errno 2]
but I can't catch that in some way and continue on. Am I missing something here or is it really expected that you use isfile() or similar before a with open() ?
use try/except to handle exception
 try:
     with open( "a.txt" ) as f :
         print(f.readlines())
 except Exception:
     print('not found')
     #continue if file not found
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With