list index()

Robert Kern robert.kern at gmail.com
Thu Aug 30 13:57:11 EDT 2007


zzbbaadd at aol.com wrote:
>> How could it not be an exception, in the plain English sense of the
>> word? Most certainly you're asking for the index because you want to do
>> something with the index. If the item is not found, you have no index,
>> so that's a special case that must be handled separately. There is no
>> logical difference between handling that special case in an except
>> clause versus handling it with an if-branch.
> 
> In my case of have done os.listdir() on two directories. I want to see
> what files are in directory A that are not in directory B.
> I have used exceptions in other languages and only do so on logic that
> should never happen.

Python is different than those languages. Exceptions are used much more
frequently in Python and often for things that will *definitely* happen not just
those things that shouldn't.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Python-list mailing list