Checking list by using of exception

Nader n.emami at
Fri Jun 13 09:37:44 CEST 2008


I read some files name from a directory and then I put these name in a
list. I will check whether it is empty or not, and I would do it with
an exception. With if statement it is very simple:

If list_of_files != ""  :            # this can be if list_of_files !=
  get the files
   there is no file

But with exception, I can write something as:

   list_of_files != []
   get the files
except ValueError:
    Print " there is no file"

What can the first statement be inside 'try' if I don't want to use if
Maybe my understandig of exception is enough to got it.

Would somebody explain me about this?


try and except   in a dircMaybe this quetion will be simple enough for

More information about the Python-list mailing list