How do I check if a file exists or not, without using the try statement?
You can write Brian's suggestion without the try:
.
from contextlib import suppress
with 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
@contextmanager
def suppress(*exceptions):
try:
yield
except exceptions:
pass