[Tutor] Equivalent exception of os.path.exists()
spir
denis.spir at free.fr
Mon Nov 30 18:08:18 CET 2009
biboy mendz <bibsmendez at gmail.com> dixit:
> http://pastebin.ca/1693849
>
> This is end-of-chapter3 exercise of the book Core Python Programming.
>
> I'm reading/searching in the book and other materials but is
> unsuccessful. There are at least 50 exceptions listed but I can't find
> anything close.
>
> I commented out my modified script to just what *should* be applicable.
> Can you please point me to the right direction? TIA.
>
>
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
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/
More information about the Tutor
mailing list