[Tutor] Equivalent exception of os.path.exists()

christopher.henk at allisontransmission.com christopher.henk at allisontransmission.com
Mon Nov 30 22:43:00 CET 2009


biboy mendz <bibsmendez at gmail.com> wrote on 11/30/2009 03:04:52 PM:

> 
> 
> spir wrote:
> >
> > What is your question?
> > If it's about the type of exception raised when os.path.exists fails, 
well, sure it's hard to find:
> >
> >   print os.path.exists("foo".bar)
> >   ==> False
> >
> > 
> My question is: i'm looking for type of exception that more or less 
> equivalent to os.path.exists attribute. I know for a fact that this 
> method yields true or false. The exercise in the book says use 
> try-except in place of os.path.exists(). That sure is (to me) quite 
> difficult task. Instead of using the available function you're are 
> tasked to do the alternative.
> 

Looking at my copy of Core Python the exercise says to follow the example 
3.2 (readTextFile.py).  There he uses the try except block around the open 
function call. 

This as mentioned could raise an IOError.  It will be triggered in a 
different manner then os.path.exist since you are now trying to open a 
file to write, instead of checking if it exist.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091130/eea64772/attachment.htm>


More information about the Tutor mailing list