list index()

Ben Finney bignose+hates-spam at benfinney.id.au
Fri Aug 31 01:31:17 CEST 2007


zzbbaadd at aol.com writes:

> 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.

You get that information unambiguously. It's an exceptional case,
since there's no index to return, so it throws an exception.

> I have used exceptions in other languages and only do so on logic
> that should never happen.

You're confusing "assert" ("this should always be true") with
"exception" ("this is an exception to the the normal flow of this
process").

An exception isn't "something that should never happen", it's
something that is entirely possible and needs to be handled somehow.

-- 
 \       "Always do right. This will gratify some people, and astonish |
  `\                                         the rest."  -- Mark Twain |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list