Quantcast
Viewing all articles
Browse latest Browse all 46

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

if os.path.isfile(path_to_file):    try:         open(path_to_file)            pass    except IOError as e:        print "Unable to open file"

Raising exceptions is considered to be an acceptable, and Pythonic, approach for flow control in your program. Consider handling missing files with IOErrors. In this situation, an IOError exception will be raised if the file exists but the user does not have read permissions.

SRC: http://www.pfinn.net/python-check-if-file-exists.html


Viewing all articles
Browse latest Browse all 46

Trending Articles



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