[Tutor] Equivalent exception of os.path.exists()
biboy mendz
bibsmendez at gmail.com
Mon Nov 30 21:04:52 CET 2009
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.
Lie and Tim's input are true that raw_input doesnt do anything or you
cant catch exception error from it. And i'm wrong in placing the
try-except clause, it should be on the fobj-open line. But im still
looking for the exception that will be raised when i input a filename
and that file already exists. I hope you get what i mean :-)
> The output beeing a logical value, there is no failure.
> A general method to get a type of exception matching a particuliar kind of error is to provoke an error of this given kind, eg:
>
> f = file("foo.bar")
> ==>
> Traceback (most recent call last):
> File "__essai__.py", line 10, in <module>
> f = file("foo.bar")
> IOError: [Errno 2] No such file or directory: 'foo.bar'
>
> In this case, the type is IOError.
>
> Denis
> ________________________________
>
> la vita e estrany
>
> http://spir.wikidot.com/
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Regards,
bibs M.
Host/Kernel/OS "cc000002695" running Linux 2.6.31-5.slh.4-sidux-686
[sidux 2009-02 Αιθήρ - kde-full - (200907141427) ]
www.sidux.com
More information about the Tutor
mailing list