Quantcast
Channel: How do I check whether a file exists without exceptions? - Stack Overflow
Viewing all articles
Browse latest Browse all 46

Answer by Chris for How do I check whether a file exists without exceptions?

$
0
0

You can write Brian's suggestion without the try:.

from contextlib import suppresswith suppress(IOError), open('filename'):    process()

suppress is part of Python 3.4. In older releases you can quickly write your own suppress:

from contextlib import contextmanager@contextmanagerdef suppress(*exceptions):    try:        yield    except exceptions:        pass

Viewing all articles
Browse latest Browse all 46

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>